montecarlo20
07-19-2013, 08:39 AM
Hi,
I am trying to create a macro that will pull information from certain areas of a word document to populate an excel spreadshee row. Im having trouble figuring out how to transfer the data from word to excel.
This is what I have so far. Basically this code should hit every inline shape (textbox) copy the contents to excel.
so box 1 should be put in a1, box 2 to b1, box 3 to c1 and so on.
I cant figure out how to get this data to excel.
Sub Document_TextBoxes()
Dim oCtl As InlineShape
Dim oTB
Dim oXLApp As Object, oXLwb As Object, oXLws As Object
Set oXLApp = CreateObject("Excel.Application")
Set oXLwb = oXLApp.Workbooks.Open("K:\Everyone\Test1.xlsm")
'~~> Work with Sheet1. Change as applicable
Set oXLws = oXLwb.Sheets(1)
'Call OpenExcelFile
For Each oCtl In ActiveDocument.InlineShapes
If oCtl.OLEFormat.ProgID = "Forms.TextBox.1" Then
Set oTB = oCtl.OLEFormat.Object
oTB.Select
Selection.Copy
End If
Next
End Sub
I am trying to create a macro that will pull information from certain areas of a word document to populate an excel spreadshee row. Im having trouble figuring out how to transfer the data from word to excel.
This is what I have so far. Basically this code should hit every inline shape (textbox) copy the contents to excel.
so box 1 should be put in a1, box 2 to b1, box 3 to c1 and so on.
I cant figure out how to get this data to excel.
Sub Document_TextBoxes()
Dim oCtl As InlineShape
Dim oTB
Dim oXLApp As Object, oXLwb As Object, oXLws As Object
Set oXLApp = CreateObject("Excel.Application")
Set oXLwb = oXLApp.Workbooks.Open("K:\Everyone\Test1.xlsm")
'~~> Work with Sheet1. Change as applicable
Set oXLws = oXLwb.Sheets(1)
'Call OpenExcelFile
For Each oCtl In ActiveDocument.InlineShapes
If oCtl.OLEFormat.ProgID = "Forms.TextBox.1" Then
Set oTB = oCtl.OLEFormat.Object
oTB.Select
Selection.Copy
End If
Next
End Sub