Opening Newly saved file with vba with randomly generated file name

Opening Newly saved file with vba with randomly generated file name

Thomas.Long
Advocate Advocate
390 Views
1 Reply
Message 1 of 2

Opening Newly saved file with vba with randomly generated file name

Thomas.Long
Advocate
Advocate

I have a program that opens an instance of an existing file and returns that file. What I want to do is call the save as command and return the new file that generates. I do not know what the name will be, because I don't type the name myself, we use a system of randomly generated numbers that are generated when the save as command is run by the program. I need to figure out a way to open and return the new file name, as I intend to pass information into it from an excel file and run some ilogic rules to reconfigure the entire thing.

 

Please note I'm running the rules from excel but have the inventor reference library enabled. 

 

Thank you

 

Private Sub CreateMomentFrameB_Click()

    Dim Doc As Object
    Dim Doc2 As Object
    Dim DLG As FileDialog
    Dim Inventor As Inventor.Application
    Dim InventorObjects As Variant
    
    InventorObjects = OpenInventorFile("C:\Work\Designs\Project Documents\EDH\Working Projects\Dynamic Base Assemblies\DynamicMomentFrameAssembly.iam", False)
    Set Inventor = InventorObjects(0)
    Set Doc = InventorObjects(1)

'This saves the file but doc is still set to the old file, so that when I run my ilogic rule it uses that rather than the freshly made file.
    Doc.Save
    
    Worksheets("PCR").Range("J" & 7) = Split(Split(Doc.FullFileName, "\")(UBound(Split(Doc.FullFileName, "\"))), ".")(0)
    
    Call RuniLogic("Master Rule", Doc, Inventor, False)
    
End Sub
0 Likes
Accepted solutions (1)
391 Views
1 Reply
Reply (1)
Message 2 of 2

philip.G
Enthusiast
Enthusiast
Accepted solution

I would just look for different properties. 

If you don't know the filename you could look for the save-date and the size of the file, or if you have access to the Iproperties  of the file you could look for the name of the part. (which I guess will stay the same.)