gregcscott
06-02-2010, 06:12 AM
Hi,
this is my first time posting, and I am looking for a way to auto process a batch of documents I have. It is a standard purchase order doc, with an embedded XLS in it, and I need to roll up all of the data. So I want to run a macro on a doc, have it save the embedded XLS as its own file with the additional structure of "_data.xls" added onto it. I have looked around the web for this, and patched together some of my own code with others and this is what I have:
Sub Extract_XLS()
Dim xlWorkbook As Excel.Workbook
Dim oDoc As Document
Dim oDcOle As Word.OLEFormat
Dim strDocName As String
ActiveDocument.Shapes("Object 5").Select
Selection.ShapeRange(1).OLEFormat.DoVerb VerbIndex:=1
strDocName = ActiveDocument.FullName
Set oDoc = ActiveDocument
Set xlWorkbook = oDcOle.Object
intPos = InStrRev(strDocName, ".")
strDocName = Left(strDocName, intPos - 2)
strDocName = strDocName & "_data" & ".xls"
xlWorkbook.SaveAs FileName:=strDocName
xlWorkbook.Close
Set xlWorkbook = Nothing
Set oDoc = Nothing
Set oDcOle = Nothing
End Sub
This runs until the bolded line, it successfully opens the embedded object in excel, but does not get any further. This is a time sensitive issue, and any expedited help would be greatly appreciated.
this is my first time posting, and I am looking for a way to auto process a batch of documents I have. It is a standard purchase order doc, with an embedded XLS in it, and I need to roll up all of the data. So I want to run a macro on a doc, have it save the embedded XLS as its own file with the additional structure of "_data.xls" added onto it. I have looked around the web for this, and patched together some of my own code with others and this is what I have:
Sub Extract_XLS()
Dim xlWorkbook As Excel.Workbook
Dim oDoc As Document
Dim oDcOle As Word.OLEFormat
Dim strDocName As String
ActiveDocument.Shapes("Object 5").Select
Selection.ShapeRange(1).OLEFormat.DoVerb VerbIndex:=1
strDocName = ActiveDocument.FullName
Set oDoc = ActiveDocument
Set xlWorkbook = oDcOle.Object
intPos = InStrRev(strDocName, ".")
strDocName = Left(strDocName, intPos - 2)
strDocName = strDocName & "_data" & ".xls"
xlWorkbook.SaveAs FileName:=strDocName
xlWorkbook.Close
Set xlWorkbook = Nothing
Set oDoc = Nothing
Set oDcOle = Nothing
End Sub
This runs until the bolded line, it successfully opens the embedded object in excel, but does not get any further. This is a time sensitive issue, and any expedited help would be greatly appreciated.