Well, I guess I spoke too soon. It worked in a test file that I set up, but
now it will not work in the actual Excel workbook that I normally use. Here
is the code:
Sub ControlWordFromXL()
Dim objWord As New Word.Application
Dim doc As Word.Document
Dim bkmk As Word.Bookmark
sWdFileName = Application.GetOpenFilename(, , , , False)
Set doc = objWord.Documents.Open(sWdFileName)
'On Error Resume Next
Sheets("LOOKUP").Activate
ActiveDocument.Variables("Broker_First_Name").Value =
Range("Broker_First_Name").Value
ActiveDocument.Variables("Broker_Last_Name").Value =
Range("Broker_Last_Name").Value
ActiveDocument.Fields.Update
'On Error Resume Next
objWord.Visible = True
End Sub
The issue is this...
Run-time error '4248':
This command is not available because no document is open.
All the relevant data is stored on a sheet called 'Lookup'. This error
message is bizarre because the Word document is open...as far as I can tell.
Does anyone know what could cause this?
Regards,
Ryan--
--
RyGuy
"ryguy7272" wrote:
> I got it to work with this logic:
> Sub PushToWord()
>
> Dim objWord As New Word.Application
> Dim doc As Word.Document
> Dim bkmk As Word.Bookmark
> sWdFileName = Application.GetOpenFilename(, , , , False)
> Set doc = objWord.Documents.Open(sWdFileName)
>
> ActiveDocument.Variables("BrokerFirstName").Value = Range("B1").Value
> ActiveDocument.Variables("BrokerLastName").Value = Range("B2").Value
>
> ActiveDocument.Fields.Update
>
> objWord.Visible = True
>
> End Sub
>
> That was significantly easier than I thought. Working with Word is usually
> work; this time it was actually fun.
>
> Thanks so much Helmut!
> Ryan--
>
> --
> RyGuy
>
>
> "Helmut Weber" wrote:
>
> > Hi Ryan,
> >
> > have a look at this one:
> >
> > Sub Makro2()
> > ActiveWindow.View.ShowFieldCodes = False
> > ActiveDocument.Variables("Tracking").Value = "Track"
> > Selection.Fields.Add _
> > Range:=Selection.Range, _
> > Type:=wdFieldEmpty, _
> > Text:="DOCVARIABLE Tracking ", _
> > PreserveFormatting:=True
> > ActiveDocument.Variables("Tracking").Value = "Another Track"
> > ActiveDocument.Fields.Update
> > End Sub
> >
> >
> > --
> > Greetings from Bavaria, Germany
> > Helmut Weber, MVP WordVBA
> > Word 2002, Windows 2000 (german versions)
> >