AnsweredAssumed Answered

Dir not working on drawings I never opened

Question asked by Alex Caicedo on Jun 22, 2018
Latest reply on Jun 29, 2018 by Alex Caicedo

Hey guys,

I have written a macro to batch print PDFs (using the one passed around here with some updates);however, there is one problem I keep having. Anytime the macro tries to open a part from PDM that I have never opened/viewed in SolidWorks before, the Dir function returns a False value and the variable is blank. I actually cut down the code to just the line that contained the Dir function so I could test out a theory:

 

Dim swApp As Object

Dim Filename As String

Sub main()

 

Filename = Dir("C:\PAS-EPDM\A Systems\ 2018\plastics\CAD\" & "360446" & "*.slddrw")

MsgBox Filename

 

'Set swApp = Application.SldWorks

End Sub

 

When I run this (knowing that that part is absolutely in that file path), the message box comes out blank. But then, when I open that part in SolidWorks from that location, close the part, then re-run the exact same macro, the message box returns "360446.slddrw" and I can open it with additional code. I tested this on several parts I've never opened before (even running the macro a couple times before opening the part) and the same thing happens.

Is there any way to get the Dir function to recognize files that are in the file path that I never opened or am I stuck only using this on Dwgs that I have opened previously?

 

Any help would be greatly appreciated!

 

Thanks

Outcomes