

I might wait until the end of the code, but that would be personal preference. If it's in order to show it to the user, for editing, then by all means. It's not necessary for manipulating a document's content via VBA. It's unsure whether you'd really need to activate this window. So declare and instantiate a variable for the Word document and use that instead of ActiveDocument: Dim objDoc as Object 'Word.Document Better to work with the application's objects, directly. In this case, as the file is in Word and not Excel, using objWord.Windows(Filename).Activate should avoid this particular error.Īs with Excel, using Active, Activate or Selection in Word VBA is unreliable and shouldn't be used unless absolutely necessary.
How to use document inspector in excel 2013 code#
The reason for the error is that this code is running in Excel, so if objWord is not used for Word syntax, and both Word and Excel use the same name for an object, VBA will try to use the Excel object model. There are a number of factors in play with this code that will or might cause problems. The requested member of the collection does not exist. Selection.MoveLeft Unit:=wdCharacter, Count:=2 Selection.PasteAndFormat (wdFormatOriginalFormatting) Selection.GoTo What:=wdGoToBookmark, Name:="" IntChoice = Application.FileDialog(msoFileDialogOpen).ShowĪnd here it breaks :( Windows(FileName).Activate Set objWord = CreateObject("Word.Application")Īpplication.FileDialog(msoFileDialogOpen).AllowMultiSelect = False "FileWithData" could be any file and that is the reason I am using OpenDialog.Įverything is working but I am stuck when it comes to Activating "FileWithData" window to start "Copying and Pasting" process. I am trying to write the VBA code to open a Word Document file ("FileWithData") and copy the information from "FileWithData" into "Template1". I have one Word Document ("Template1") opened already.
