N
nannon8
I am a relative beginner with VBA, and am trying to set up a template
in word that retieves data from excel and inserts it at a bookmarked
place in a word document. The problem is that the excel workbook will
change each time the template is used, as the data to be retrieved is a
monthly report, which will be saved with a different name from the
previous month, although in the same folder.
Ideally I would like for the user to be able to select the workbook to
be used from a dropdown list.
I have managed to get the following code to work for a workbook with a
static filename and path, but can't work out how to allow the user to
choose a workbook.
Dim myWB As Excel.Workbook
Set myWB = _
GetObject("C:\test")
Selection.GoTo _
What:=wdGoToBookmark, _
Name:="text"
Selection.TypeText _
(myWB.Sheets("Test").Range("text1"))
Set myWB = Nothing
in word that retieves data from excel and inserts it at a bookmarked
place in a word document. The problem is that the excel workbook will
change each time the template is used, as the data to be retrieved is a
monthly report, which will be saved with a different name from the
previous month, although in the same folder.
Ideally I would like for the user to be able to select the workbook to
be used from a dropdown list.
I have managed to get the following code to work for a workbook with a
static filename and path, but can't work out how to allow the user to
choose a workbook.
Dim myWB As Excel.Workbook
Set myWB = _
GetObject("C:\test")
Selection.GoTo _
What:=wdGoToBookmark, _
Name:="text"
Selection.TypeText _
(myWB.Sheets("Test").Range("text1"))
Set myWB = Nothing