5

I have problem with File System Object late binding. This is my code:

Dim WordA As Object 'aplikacja programu Word
Dim PlikW As Object 'plik Worda
Dim Nazwa As Object 'obszar Worda ze zdefiniowaną nazwą
Dim Zakres As Range 'zakres danych używany do wiadomości
Dim NrRaportu As Integer 'Numer tworzonego raportu
Dim Katalog As String 'pełna nazwa katalogu, w którym zapisywane są wiadomości
Const Raport_szablon = "Raport_szablon.docx" 'zazwa pliku z szablonem
Dim fso As Object 'Objekt FileSystemObject

'1. Wczytanie danych
Set Zakres = Range("R2:Z" & Cells(Rows.Count, "R").End(xlUp).Row)
Katalog = ThisWorkbook.Path & "\Raporty"
Set fso = CreateObject("FileSystemObject")
If Not fso.FolderExists(Katalog) Then _
    fso.CreateFolder (Katalog)

and I get a message that

"ActiceX component can't create object"

.

Community
  • 1
  • 1
Arkadiusz
  • 369
  • 5
  • 18
  • 1
    Possible duplicate of [How do I use FileSystemObject in VBA?](https://stackoverflow.com/q/3233203/11683) – GSerg May 11 '18 at 20:55
  • 7
    You need `Set fso = CreateObject("Scripting.FileSystemObject")` rather than simply `Set fso = CreateObject("FileSystemObject")` – John Coleman May 11 '18 at 21:00
  • You are right, many thanks! Do you happen to know why using late binding I can't save files in PDF format? Using early binding it works well. Here's my code: PlikW..ExportAsFixedFormat OutputFileName:=Katalog & "\" & Marka & ".pdf", ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False – Arkadiusz May 11 '18 at 21:05
  • 1
    Put `Option Explicit` on top [to learn why](https://stackoverflow.com/a/14122422/11683). – GSerg May 11 '18 at 21:12
  • Late vs. early binding should have zero implications as to the functionality of the created objects. – John Coleman May 11 '18 at 21:16
  • 3
    @JohnColeman [Apparently not](https://stackoverflow.com/a/44862518/11683) (although it's not the culprit here). – GSerg May 11 '18 at 21:17
  • i received a message: Invalid procedure call or argument – Arkadiusz May 11 '18 at 21:22
  • 1
    @GSerg Interesting. Learn something new every day. – John Coleman May 11 '18 at 21:34
  • Its needed also to register the underlaying dll as a reference in the reference manager. – Thomas Ludewig Jan 14 '22 at 13:42

1 Answers1

0

You need also to use the reference manger and add the dll / ocx to the project. c:\windows\system32\wshom.ocx if i remember right

Thomas Ludewig
  • 696
  • 9
  • 17