the problem is not the unload function or the hide.
I can't get the "wait 10 seconds" if no input then continue macro to work.
I've been in contact with API support. The userform timer functionality i was looking for, while available in excel and ms word, is not included in the SW libaray. Their response was this:
What we need is a timer event based library for VBA
Once the timer event functionality is available then we need to also need keyboard and mouse event handling.
Here is general algorithm
1] when form is displayed, start timers 2] in mouse and keyboard events reset timer 3] on timer end close form
Currently the timer functionality is not available.
So basically not possible.
Our company has a foler heirarchy of where files are supposed to go, Model file, DXF file, BOM file etc.
So everytime I save a PDF I have to traverse the heiarachy to the "Published" folder, this macro saves the drawing out as a PDF in the correct file for me.
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Prop_N() As String
Dim iReply As String
Dim saveDir As String, FileDir As String, FileName As String, sRev As String, sP_Numb As String, sStatus As String
Dim FileExt(1 To 2) As String
Dim FileChk As Boolean
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
'check that a File is open
If swDoc Is Nothing Then
iReply = "No File open"
Set swModelDocExt = swDoc.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
Prop_N() = Split("Status, PROJECT NO, Revision, CheckedBy, Description", ", ")
'iReply = "WARNING! Macro underdevelopment"
'Checks to make sure current file is a drawing
If swDoc.GetType <> swDocDRAWING Then
MsgBox "Warning, File not Drawing!"
sRev = 1
Dim I As Integer
Dim val As String, valout As String
For I = 0 To UBound(Prop_N)
boolstatus = swCustProp.Get4(Prop_N(I), False, val, valout)
'Debug.Print "Value: " & val
'Debug.Print "Evaluated value: " & valout
'Debug.Print "Up-to-date data: " & boolstatus
Select Case I
sStatus = valout
sP_Numb = valout
sRev = valout
If valout <> " " Or valout <> "" Then
Debug.Print "Checked by: " & valout
FileChk = True
FileChk = False
Debug.Print "Description: " & valout
MsgBox "Unrecognized Property"
'set up file extensions
FileExt(1) = ".pdf"
FileExt(2) = ".edrw"
'Gets current file name and path
FileName = swDoc.GetPathName
'strips solidworks extension off name and replaces with pdf
FileDir = Left(FileName, Len(FileName) - 7)
If InStr(FileDir, "Model") = 0 Then
saveDir = Left(FileDir, InStrRev(FileDir, "\"))
Else: saveDir = Left(FileDir, InStr(FileDir, "Model") + 5) & "\Published\"
FileName = Right(FileDir, Len(FileDir) - InStrRev(FileDir, "\"))
If sRev = CStr("1") Or sRev = "" Then
sRev = ""
sRev = "_R" & sRev
'Project Number Format
sP_Numb = Mid(sP_Numb, 2, 5)
If IsNumeric(sP_Numb) = True Then
sP_Numb = "P" & sP_Numb
If InStr(FileName, sP_Numb) = 0 Then
FileName = sP_Numb & "_" & FileName
sP_Numb = ""
For I = 1 To 2
' File checked Msg
If sStatus = "FOR FAB" And FileChk <> True Then
MsgBox "File not checked."
boolstatus = FileSave(saveDir, FileName, sRev, FileExt(I))
If sStatus <> "FOR FAB" Then
Function FileSave(DIR As String, NAME As String, REV As String, EXT As String)
Application.SldWorks.ActiveDoc.Extension.SaveAs DIR & NAME & REV & EXT, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, longstatus, longwarnings
'Debug.Print "Error: " & longstatus & vbNewLine & "Warning: " & longwarnings
Do you need the timer for closing the userform only?
Have you tried the SLEEP function?
I have not tried sleep, I've never used sleep before. Would sleep allow me to cause the userform to close after a period of no input?
Sorry my mistake, SLEEP is for putting a pause and NOT closing the form. I must have been in sleep when i posted that.
Let me see if there is any option in VB.NET.
Have you thought of using the excel macro to save PDF from SOLIDWORKS? This way you may be able to use the timer option.
But again why you need a userform for the macro?
The reason I was trying to have a userform was to allow if the person trying to run the macro wasn't on a drawing having the option to to just proceed anyway or tweak the print settings.