I have an issue with the VB code I have written in VBA 6.5. We have today moved to a new environment and all our systems have been upgraded from Office 2003, Windows XP, VBA 6.5 to Office 2010, Windows 7, VBA 7.
I have a word document which I have now saved from .doc to .docm because of all the macros. When a command button on this document is pressed it opens up another word document that is not visible to the user. It adds numerous data to the new document and saves it. One of the things it does is adds information in the header. This all used to work fine until the changes today. Now everything works fine but the information that is meant to go into the header is actually put into the body of the document where the code is running from, i.e the wrong document. Can anyone see anything in the code that might be causing this to happen? I wouldn’t say I am particularly advanced in VB.
'Add job name and ref to the header If Documents(matrixdoc).ActiveWindow.View.SplitSpecial <> wdPaneNone Then Documents(matrixdoc).ActiveWindow.Panes(2).Close End If If Documents(matrixdoc).ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow.ActivePane.View.Type = wdOutlineView Then Documents(matrixdoc).ActiveWindow.ActivePane.View.Type = wdPrintView End If Documents(matrixdoc).ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader Selection.MoveDown Unit:=wdLine, Count:=2 Selection.EndKey Unit:=wdLine Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.TypeText Text:=job_Name Selection.MoveDown Unit:=wdLine, Count:=1 Selection.TypeText Text:=job_Ref Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.EndKey Unit:=wdLine Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.TypeText Text:=Date Selection.MoveUp Unit:=wdLine, Count:=1 Selection.TypeText Text:=Initials Documents(matrixdoc).ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Try replacing lines 1 to 8 with this line:
Open in new window