Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a function I've been writing that is supposed to take a boolean that specifies whether the file is a new file to be opened from a template or is an existing file and then either the template to be used or the file name and location.
Unfortunately when I try to ask for a new file its telling me that upon returning the file that I'm having a type mismatch. What's odd is that I'm setting it to the exact same variable (type object) as whenever I open an existing file and they're both returning a document type. Any idea what's going on?
'Opens an existing file or creates a new one. Returns the file reference 'Pass it the template you wish to use for a new document. Acceptable template files listed below ' Assembly (Imperial).iam, ASTM Angle.ipt, ASTM Channel.ipt, ASTM Miscellaneous Channel.ipt, ASTM Rectangular Tube.ipt, ASTM Wide Flange Beam.ipt, _ ' Copper Bar Part (Imperial).ipt, Grating Material Template (Imperial).ipt, Non-Metallic Sheet Outsourced.ipt, Part - Other (Imperial).ipt, _ ' Roll Fromed Coil.ipt, Sheet Metal Part (Imperial).ipt, Weldment (Imperial).iam '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Private Function OpenInventorFile(FileName As String, NewFile As Boolean) As Object 'On Error Resume Next Dim Doc As Object Dim Inventor As Object Dim InvVBAProject As Object Dim InvVBAModule As Object Dim InvVBAProcedureToRun As Object Dim Location As String Dim TemplateName As String 'Get open instance of inventor or open one if nothing is found Set Inventor = GetObject(, "Inventor.Application") 'If Err Then ' Err.Clear 'Set Inventor = CreateObject("Inventor.Application") 'End If Inventor.Visible = True If NewFile = False Then Set Doc = Inventor.Documents.Open(FileName) Else Location = "C:\Work\Designs\Templates\2013\Inventor Templates\Imperial\" TemplateName = Location & FileName Set Doc = Inventor.Documents.Add(TemplateName) End If Set InvVBAProject = Inventor.VBAProjects.Item(1) Set InvVBAModule = InvVBAProject.INventorVBAComponents.Item(2) Set InvVBAProcedureToRun = InvVBAModule.InventorVBAMembers.Item(1) InvVBAProcedureToRun.Execute OpenInventorFile = Doc End Function '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Solved! Go to Solution.