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
Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try
Sub Copy_One_File()
    FileCopy "M:\General\MyFolder\TecDataSheet.docm", ThisWorkbook.Path & "\TecDataSheet.docm"
End Sub

Open in new window

EDIT Corrected code

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GrahamSkanRetiredCommented:
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

0
Andreas HermleTeam leaderAuthor Commented:
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
0
Andreas HermleTeam leaderAuthor Commented:
Hi Rgonzo, great, works as desired. Thank you very much for it.

Regards, Andreas
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.