A
A
adam186442022-04-10 19:41:06
Visual Basic
adam18644, 2022-04-10 19:41:06

How to copy open vba file with script?

Damn guys, you can talk as much as you like, Google to help read the documentation. but alas, I found everything, I tried all the variations
in this case, it gives an error 424
for example, I inserted the path of the pace, I understand that it is most likely incorrectly indicated, but I tested for an error exactly the same

(ThisWorkbook.Path & "\doc.docm")
But the actual code itself

Sub WorkBook_open()

Set fso = CreateObject("Scripting.FileSystemObject")

Set File = fso.GetFile(ThisWorkbook.Path & "\doc.docm")
Set File = fso.Copy("%Temp%\d6c.docm")
End Sub


I will be very grateful if you help in resolving the issue, and do not start pouring in an evaluative opinion

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Akina, 2022-04-10
@Akina

What for was it to delete the previous version of the question?
Okay, I'll repeat. The FileSystemObject does not have a Copy method, the Folder and File objects do. Therefore,
Set File = fso.GetFile(ThisWorkbook.Path & "\doc.docm")
Set File = fso File.Copy("%Temp%\d6c.docm")
PS. What is an "open file", where, by whom and in general why is it open - I did not understand.

D
Denis _______________, 2022-04-11
@LuchS-lynx

I do this with a VBA macro in Excel

Dim Wd As Object, Wapp As Object 
            Let Shablon = ThisWorkbook.Path + "\Шаблоны аддонов\" + WorldShablonFileName
            Let ИмяФайла =  ThisWorkbook.Path + "\" + "Имя файла.docx"

            Rem -= копируем шаблон по новому пути =-
            Set Wapp = CreateObject("Word.Application"): AppWord.Visible = False
            Set Wd = Wapp.Documents.Open(Shablon, ReadOnly:=True)
                Wd.SaveAs Filename:=ИмяФайла, FileFormat:=wdFormatXMLDocument
                Wd.Close False: Set Wd = Nothing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question