icepirates1234
MIS
Hello,
What Im trying to develop is this:
(I have a Word document, that pulls information from an Excel document)
(Thats essintially what this script does)
A Macro that upon opening of a Word Document, a Macro executes and updates the information a Word Document from a source file which is an Excel document...You might ask why Im not using Paste-Special, to establish data-links - it's mainly because paste-special doesn't have the functionality I need.
For instance:
In my Word document I have:
John Smith
Joe Smith
Bob Smith
And in the Excel sheet, in Column A, I have a list of Projects
In column B there is a name of a person assigned to that project (John, Joe or Bob)
The Word document needs to pull all projects from the Excel sheet for John, and list them under John in the Word Document, it needs to then pull all projects listed in the Excel sheet for Joe and list them under Joe...and so on...
So right now where Im at this point with the code, I can get Word to retrieve a few things out of the Excel sheet, but not all the information I described above.
I was thinking - is there a way to use my command button I have set up, and this statement:
Private Sub CommandButton1_Click()
HideListBoxes
Dim myWB As Excel.Workbook
Set myWB = GetObject("H:\Projects\Update Agenda Spreadsheet\alpha-test\AboutWordExcel.xls")
Selection.GoTo What:=wdGoToBookmark, Name:="TimeOverdue"
Selection.TypeText (myWB.Sheets("PayHist").Range("Time_Overdue"))
Set myWB = Nothing
End Sub
And where it says, .Range("Time_Overdue")
change that do a cell range, like "B2"
Ive tried altering the code and applying just a cell range and Word doesn't seem to like that...
Does anyone have any advice?
I have some attached sample data. (Extract to C:\alpha-test)
What Im trying to develop is this:
(I have a Word document, that pulls information from an Excel document)
(Thats essintially what this script does)
A Macro that upon opening of a Word Document, a Macro executes and updates the information a Word Document from a source file which is an Excel document...You might ask why Im not using Paste-Special, to establish data-links - it's mainly because paste-special doesn't have the functionality I need.
For instance:
In my Word document I have:
John Smith
Joe Smith
Bob Smith
And in the Excel sheet, in Column A, I have a list of Projects
In column B there is a name of a person assigned to that project (John, Joe or Bob)
The Word document needs to pull all projects from the Excel sheet for John, and list them under John in the Word Document, it needs to then pull all projects listed in the Excel sheet for Joe and list them under Joe...and so on...
So right now where Im at this point with the code, I can get Word to retrieve a few things out of the Excel sheet, but not all the information I described above.
I was thinking - is there a way to use my command button I have set up, and this statement:
Private Sub CommandButton1_Click()
HideListBoxes
Dim myWB As Excel.Workbook
Set myWB = GetObject("H:\Projects\Update Agenda Spreadsheet\alpha-test\AboutWordExcel.xls")
Selection.GoTo What:=wdGoToBookmark, Name:="TimeOverdue"
Selection.TypeText (myWB.Sheets("PayHist").Range("Time_Overdue"))
Set myWB = Nothing
End Sub
And where it says, .Range("Time_Overdue")
change that do a cell range, like "B2"
Ive tried altering the code and applying just a cell range and Word doesn't seem to like that...
Does anyone have any advice?
I have some attached sample data. (Extract to C:\alpha-test)