Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulate EXCEL file from WORD macro.. HOW??

Status
Not open for further replies.

SSJpn

Technical User
Oct 7, 2002
259
US
From a WORD macro how do I go about

-Open Excel
-Open a specific file (C:\temp.xls)
-Enter "15" in cell "B5" of sheet "Blue"
-Save changes
-Close workbook,Excel

Where is a good site where I can go to learn more about VBA and manipulating different Office applications from the same macro?
 
hiii, i am doing the same, manipulating excel file from word. I use the following code that i am pasting below, hope it helps, btw a good site for help on this is
here it goes, let me know if you need any help

First set a reference to Excel (in the VB Editor, select Tools + References).

Sub WorkOnAWorkbook()

Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Dim ExcelWasNotRunning As Boolean
Dim WorkbookToWorkOn As String

'specify the workbook to work on
WorkbookToWorkOn = "C:\My Documents\myworkbook.xls"

'If Excel is running, get a handle on it; otherwise start a new instance of Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")

If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If

On Error GoTo Err_Handler

'If you want Excel to be visible, you could add the line: oXL.Visible = True here; but your code will run faster if you don't make it visible

'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn)

'Process each of the spreadsheets in the workbook
For Each oSheet In oXL.ActiveWorkbook.Worksheets
'put guts of your code here
'get next sheet
Next oSheet

If ExcelWasNotRunning Then
oXL.Quit
End If

'Make sure you release object references.
Set oRng = Nothing
Set oSheet = Nothing
Set oWB = Nothing
Set oXL = Nothing

'quit
Exit Sub

Err_Handler:
MsgBox WorkbookToWorkOn & " caused a problem. " & Err.Description, vbCritical, "Error: " _
& Err.Number
If ExcelWasNotRunning Then
oXL.Quit
End If

End Sub
 
Got it.. and it works..

Thanks,

SSJpn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top