Open a Word document from VBA code
Arnaud T
-
Arnaud T -
Arnaud T -
Hello,
I would like to create a VBA program that opens a Word file located in the folder of the current Excel file. (I'll spare you the rest of the code which is still in progress)
My code is as follows:
Dim objWord As New Word.Application
FilePath = ThisWorkbook.Path
strFile = FilePath & "\MÉMOIRE TECHNIQUE - Vierge.docx"
objWord.Documents.Open strFile
The problem is that when launching the macro, nothing happens, except that a WINWORD.EXE process appears in the task manager...
If I rerun the macro, a "File in use" application appears in the task manager, when I click on it, it tells me that the file is locked for editing.
Any ideas?
Thanks in advance to everyone.
Configuration: Windows 7 / Chrome 47.0.2526.111
I would like to create a VBA program that opens a Word file located in the folder of the current Excel file. (I'll spare you the rest of the code which is still in progress)
My code is as follows:
Dim objWord As New Word.Application
FilePath = ThisWorkbook.Path
strFile = FilePath & "\MÉMOIRE TECHNIQUE - Vierge.docx"
objWord.Documents.Open strFile
The problem is that when launching the macro, nothing happens, except that a WINWORD.EXE process appears in the task manager...
If I rerun the macro, a "File in use" application appears in the task manager, when I click on it, it tells me that the file is locked for editing.
Any ideas?
Thanks in advance to everyone.
Configuration: Windows 7 / Chrome 47.0.2526.111
6 answers
-
-
-
Do you want to talk about the Excel or PDF icon to put in Word?
--
@+ The Woodpecker-
No, directly the Excel or the PDF as an image (so that it can be printed on paper, this document will serve as a technical memo to be sent with our responses to calls for tenders).
In fact, my program generally does the following:
When opening Excel, all the names of my subfolders appear in column B (for example, the name of the equipment we use, the operational manuals used, etc...) which represents about a hundred subfolders.
Then, you simply check the boxes in column A for the subfolders you wish to include in your technical memo. When you click a button, the macro runs and allows you to:
- Open the blank technical memo (with the formatting).
- Insert images/Excel/PDF files present in the checked subfolders into Word (I have created bookmarks to indicate where to insert my images).
You just have to print the folder to send it by mail.
So for now everything works, I can integrate the images, but I would like to insert, for example, a PDF or an Excel file as an image.
Thank you!
-
-
For PDFs, the image is copied to the clipboard, you just need to paste it into your Word document:
http://www.infocom21.net/spip.php?article44
For Excel, you can take a screenshot of your sheet
--
@+ The Woodpecker -
If you save the image obtained this way, you can use it.
--
@+ The Woodpecker -
After putting the image in the clipboard, you can paste it, which saves you from having to save it:
http://www.faqword.com/index.php/word/tutos/toutes-versions/136-le-presse-papiers-office
--
See you later, Le Pivert