View Single Post
 
Old 10-14-2011, 05:02 PM
donlincolnmsof donlincolnmsof is offline Windows 7 64bit Office 2003
Advanced Beginner
 
Join Date: Oct 2011
Posts: 36
donlincolnmsof is on a distinguished road
Smile Call Excel from Word

Hello

I'm looking for a macro that will Call Excell from word and open a file called "Dummy.xls" and select the column A and copy the whole column and then exit excell and paste that data in to word.

Any help will be greatly appreciated.

thanks.



Below is a bit of a code that i got but the copy part is not working.



Sub CreateNewExcelWB()
' to test this code, paste it into a Word module
' add a reference to the Excel-library
' create a new folder named C:\Foldername or edit the filnames in the code
'Dim xlApp As Excel.Application
'Dim xlWB As Excel.Workbook
Dim i As Integer
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
' Set xlWB = xlApp.Workbooks.Add ' create a new workbook
' or
Set xlWB = xlApp.Workbooks.Open("C:\mydocs\windows\desktop\pr ospecting\dummy.xls")
' open an existing workbook
' example excel operations
With xlWB.Worksheets(1)
Columns("A:A").Select
Selection.Copy

' If Dir("C:\Foldername\MyNewExcelWB.xls") <> "" Then
' Kill "C:\Foldername\MyNewExcelWB.xls"
' End If
' .SaveAs ("C:\Foldername\MyNewExcelWB.xls")
End With
xlWB.Close False ' close the workbook without saving
xlApp.Quit ' close the Excel application
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
Reply With Quote