Object variable or With block not set hatası

Katılım
12 Eylül 2020
Mesajlar
174
Excel Vers. ve Dili
365 ev
Öncelikle merhabalar, bir excel dosyası üzerinde filtrelediğim PDF isimlerini kullanarak bunların URL sini bir sütuna yazdırıyorum, amacım bu URL leri kullanarak toplu bir şekilde çıktı almak. Tıkandığım nokta ise döng aşağıda yazan kod içinde
Kod:
If Sh Is Nothing Then Set Sh = CreateObject("Shell.Application")
kısmında " Object variable or With block not set" hatası vermesi, 2 gündür arıyorum çözüm bulamadım.
Kod:
Public Sub Print_PDFs()

    Dim PDFsFolder As String
    Dim PDFfile As String
    Dim r As Long
  
    PDFsFolder = "\\192.168.1.191\04-proje$\Teknik Resimler\Fkt Teknik Resimler\"      'CHANGE THIS
  
    If Right(PDFsFolder, 1) <> "\" Then PDFsFolder = PDFsFolder & "\"
  
    With Sheets("siparis")
        For r = 2 To .Cells(.Rows.Count, "G").End(xlUp).Row
            PDFfile = PDFsFolder & .Cells(r, "G").Value & ".pdf"
            If PDFfile <> vbNullString Then
                Print_PDF PDFsFolder & PDFfile
            End If
        Next
    End With
  
End Sub


Private Sub Print_PDF(PDFfile As String)
 
    Static Sh As Object 'Shell32.Shell

    
    Dim folder As Variant, fileName As Variant
  
    folder = Left(PDFfile, InStrRev(PDFfile, "\"))
    fileName = Mid(PDFfile, InStrRev(PDFfile, "\") + 1)
  
    If Sh Is Nothing Then Set Sh = CreateObject("Shell.Application")
    Sh.Namespace(folder).Items.Item(fileName).InvokeVerb "Print"

End Sub
 

Muzaffer Ali

Destek Ekibi
Destek Ekibi
Katılım
5 Haziran 2006
Mesajlar
6,153
Excel Vers. ve Dili
2019 Türkçe
Bir sorun görünmüyor fakat aşağıdaki gibi de deneyebilirsiniz.
Eğer yine de olmazsa dosyanızı ekleyin kontrol edelim.

Kod:
Dim Sh As Object 'Shell32.Shell

Public Sub Print_PDFs()
    Dim PDFsFolder As String
    Dim PDFfile As String
    Dim r As Long
    Set Sh = CreateObject("Shell.Application")
    PDFsFolder = "\\192.168.1.191\04-proje$\Teknik Resimler\Fkt Teknik Resimler\"      'CHANGE THIS
    If Right(PDFsFolder, 1) <> "\" Then PDFsFolder = PDFsFolder & "\"
    With Sheets("siparis")
        For r = 2 To .Cells(.Rows.Count, "G").End(xlUp).Row
            PDFfile = PDFsFolder & .Cells(r, "G").Value & ".pdf"
            If PDFfile <> vbNullString Then
                Print_PDF PDFsFolder & PDFfile
            End If
        Next
    End With
End Sub

Private Sub Print_PDF(PDFfile As String)
    Dim folder As Variant, fileName As Variant
    folder = Left(PDFfile, InStrRev(PDFfile, "\"))
    fileName = Mid(PDFfile, InStrRev(PDFfile, "\") + 1)
    Sh.Namespace(folder).Items.Item(fileName).InvokeVerb "Print"
End Sub
 
Katılım
12 Eylül 2020
Mesajlar
174
Excel Vers. ve Dili
365 ev
Bir sorun görünmüyor fakat aşağıdaki gibi de deneyebilirsiniz.
Eğer yine de olmazsa dosyanızı ekleyin kontrol edelim.

Kod:
Dim Sh As Object 'Shell32.Shell

Public Sub Print_PDFs()
    Dim PDFsFolder As String
    Dim PDFfile As String
    Dim r As Long
    Set Sh = CreateObject("Shell.Application")
    PDFsFolder = "\\192.168.1.191\04-proje$\Teknik Resimler\Fkt Teknik Resimler\"      'CHANGE THIS
    If Right(PDFsFolder, 1) <> "\" Then PDFsFolder = PDFsFolder & "\"
    With Sheets("siparis")
        For r = 2 To .Cells(.Rows.Count, "G").End(xlUp).Row
            PDFfile = PDFsFolder & .Cells(r, "G").Value & ".pdf"
            If PDFfile <> vbNullString Then
                Print_PDF PDFsFolder & PDFfile
            End If
        Next
    End With
End Sub

Private Sub Print_PDF(PDFfile As String)
    Dim folder As Variant, fileName As Variant
    folder = Left(PDFfile, InStrRev(PDFfile, "\"))
    fileName = Mid(PDFfile, InStrRev(PDFfile, "\") + 1)
    Sh.Namespace(folder).Items.Item(fileName).InvokeVerb "Print"
End Sub
yoğunluktan dolayı anca bakabildim kusura bakmayın, fakat aynı hatayı vermeye devam ediyor
 
Üst