Avatar of Andreas Hermle
Andreas Hermle
Flag for Germany asked on

copy a docm-file from a fixed folder location into the folder of the currently active workbook using VBA

Dear Experts:

I would like to copy a Word-File named 'TecDataSheet.docm' from 'M:\General\MyFolder\TecDataSheet.docm' into the folder of the currently open excel file.

That is …
… if the excel file from which the macro is activated, happens to reside in the folder C:\MyDocuments\.. the macro has to copy the above file (TecDataSheet.docm) from M:\General\MyFolder\TecDataSheet.docm into this folder (C:\MyDocuments\..)


Help is much appreciated. Thank you very much in advance. Regards, Andreas
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Andreas Hermle

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
GrahamSkan

Hi Andreas, I take it that (C:\MyDocuments\..) means C:\MyDocuments or any sub folder within it.
If so, I think this should do it
Sub CopyDocFile()
    If InStr(1, ThisWorkbook.Path, "C:\MyDocuments\", vbTextCompare) = 1 Then
        FileCopy "M:\General\MyFolder\TecDataSheet.docm", ThisWorkbook.Path & "\TecDataSheet.docm"
    End If
End Sub

Open in new window

Andreas Hermle

ASKER
Hi Graham,

I may have not been very clear in my requirements, sorry. This C:\MyDocuments is just an example, it could be any folder in any drive where the currently open workbook is located. Therefore your code, regrettably is of no use to me. However, It could come in handy in other circumstances. Anyhow, thank you very much for your great support. :-)

Regards, Andreas
Andreas Hermle

ASKER
Hi Rgonzo, great, works as desired. Thank you very much for it.

Regards, Andreas
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes