Opening, updating then closing file in VBA

Opening, updating then closing file in VBA

Anonymous
Not applicable
4,847 Views
5 Replies
Message 1 of 6

Opening, updating then closing file in VBA

Anonymous
Not applicable
I am trying to open an assembly file in excel by using a macro. In addition to opening I just want to update the parameters in Inventor file that are linked to excel spreadsheet. Then it would be nice have the macro also close inventor.

I am a novice VBA Programmer. Any direction on the types of code that I should use would be appreciated.
0 Likes
4,848 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
pol00002,
try this {code}
'opens excel sheet:
Dim oExclApp As Excel.Application
Set oExclApp = New Excel.Application
oExclApp.Visible = True

Dim oExclDoc As Workbook
Set oExclDoc = oExclApp.Workbooks.Open("FULLPATHOFYOUREXCELFILE")

oExclApp.ActiveWorkbook.Saved = True
oExclApp.Quit

'opens file:
ThisApplication.SilentOperation = True
Set oInv = ThisApplication.Documents.Open("FULLPATHOFYOURINVENTORFILE")

'updates file:
Dim oCommandMgr As CommandManager
Set oCommandMgr = ThisApplication.CommandManager

Dim oControlDef As ControlDefinition
Set oControlDef = oCommandMgr.ControlDefinitions.Item( _
"AppLocalUpdateCmd")
Call oControlDef.Execute
DoEvents

oInv.close False

ThisApplication.SilentOperation = False
{code}

This code will all run from within Inventor. It will first open up your spreadsheet and save it so Inventor will realize it's internal version is out of date and get the newest version. Then It will open your inventor file, do a local update, and close itself.
Message 3 of 6

Anonymous
Not applicable
not sure *how* novice a VBA programmer you are, but if the code posted above errors out, click "Tools", "References", then select MicroSoft Excel Object Library. It wont be worded exactly as such; there will be a number included, like "MicroSoft Excel 12.0 Object Library", or "MicroSoft Excel 11.0 Object Library', etc.
0 Likes
Message 4 of 6

Anonymous
Not applicable
Oh yeah, sorry. Forgot about that part.
0 Likes
Message 5 of 6

Anonymous
Not applicable
That will work fine as long as you don't plan on
distributing the code to other systems that
MIGHT have a different version of Excel installed.
In that case you have to load the references
in the actual code instead, similar to:

Dim objExcel As Object
'Dim objWorkbook As Excel.Workbook
Dim objWorkbook As Object
'Dim objWorksheet As Excel.WorkSheet
Dim objWorksheet As Object



'On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If Err.Number Then
Err.Clear
Set objExcel = CreateObject("Excel.Application")
If Err.Number Then
MsgBox "Can't open Excel."
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
Exit Sub
End If
End If
Set objWorkbook = objExcel.Workbooks.Open(strOpenName)


jknoll wrote:
> Oh yeah, sorry. Forgot about that part.
0 Likes
Message 6 of 6

Anonymous
Not applicable


Bob and jk, it sounds like the OP wants to go the other way (i.e. use Excel macro and get Inventor.Application object).

0 Likes