Macro to copy Filename to clipboard
Macro to copy Filename to clipboard
(OP)
Looking for some help to make message box disappear after a few seconds.
At the end of my script I would like the msgbox to show, but automatically close after 2 seconds without clicking the ok button.
I have changed my last line from a msgbox to a wscript popup to hopefully make it timeout after 2 seconds.
Here is the code:
Sub CATMain()
Dim doc1 as Document
Set doc1 = CATIA.ActiveDocument
Dim Choice As String
'display an input box asking for file name format choice
Choice = InputBox( "1 MyFile" & vbCrLf & "2 MyFile.CATPart" & vbCrLf & "3 C:\directory\MyFile.CATPart", "Choose 1, 2 or 3", "1")
If Choice = 1 then
'get base file name without extension
sString = CreateObject("scripting.filesystemobject").GetBaseName(doc1.FullName)
ElseIf Choice = 2 Then
'get Complete FileName
sString = CreateObject("scripting.filesystemobject").GetFilename(doc1.FullName)
Else
'get absolute path name and extension
sString = CreateObject("scripting.filesystemobject").GetAbsolutePathname(doc1.FullName)
End If
'copy variable to clipboard
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")
Set oWrite = oExec.stdIn
oWrite.WriteLine sString
oWrite.Close
'MsgBox sString, ,"text copied to ClipBoard"
CreateObject("WScript.Shell").Popup sString, 2,"text copied to ClipBoard"
End Sub
Thanks,
Rick
At the end of my script I would like the msgbox to show, but automatically close after 2 seconds without clicking the ok button.
I have changed my last line from a msgbox to a wscript popup to hopefully make it timeout after 2 seconds.
Here is the code:
Sub CATMain()
Dim doc1 as Document
Set doc1 = CATIA.ActiveDocument
Dim Choice As String
'display an input box asking for file name format choice
Choice = InputBox( "1 MyFile" & vbCrLf & "2 MyFile.CATPart" & vbCrLf & "3 C:\directory\MyFile.CATPart", "Choose 1, 2 or 3", "1")
If Choice = 1 then
'get base file name without extension
sString = CreateObject("scripting.filesystemobject").GetBaseName(doc1.FullName)
ElseIf Choice = 2 Then
'get Complete FileName
sString = CreateObject("scripting.filesystemobject").GetFilename(doc1.FullName)
Else
'get absolute path name and extension
sString = CreateObject("scripting.filesystemobject").GetAbsolutePathname(doc1.FullName)
End If
'copy variable to clipboard
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")
Set oWrite = oExec.stdIn
oWrite.WriteLine sString
oWrite.Close
'MsgBox sString, ,"text copied to ClipBoard"
CreateObject("WScript.Shell").Popup sString, 2,"text copied to ClipBoard"
End Sub
Thanks,
Rick





RE: Macro to copy Filename to clipboard
You can do it very simple in vba but not in CATScript or catvbs...
Now, you can use workaround... example in catvbs
CODE --> catvbs
Sub CATMain() Dim doc1 ''as Document Set doc1 = CATIA.ActiveDocument Dim Choice ''As String 'display an input box asking for file name format choice Choice = InputBox( "1 MyFile" & vbCrLf & "2 MyFile.CATPart" & vbCrLf & "3 C:\directory\MyFile.CATPart", "Choose 1, 2 or 3", "1") If Choice = 1 then 'get base file name without extension sString = CreateObject("scripting.filesystemobject").GetBaseName(doc1.FullName) ElseIf Choice = 2 Then 'get Complete FileName sString = CreateObject("scripting.filesystemobject").GetFilename(doc1.FullName) Else 'get absolute path name and extension sString = CreateObject("scripting.filesystemobject").GetAbsolutePathname(doc1.FullName) End If 'copy variable to clipboard Set WshShell = CreateObject("WScript.Shell") Set oExec = WshShell.Exec("clip") Set oWrite = oExec.stdIn oWrite.WriteLine sString oWrite.Close '--------------------------------- delay = 3 'seconds Set fso = CreateObject("Scripting.FileSystemObject") Enterfile = "c:\Temp\temp.vbs" Set shell = CreateObject("Wscript.Shell") T = "Set Shell = WScript.CreateObject( """ & _ "WScript.Shell" & """ )" & vbnewline T = T & "wscript.sleep " & delay & " * 1000" & vbcrlf T = T & "Shell.sendkeys vbCr" & vbcrlf T = T & "wscript.quit" 'writes temp file Set OutStream=fso.CreateTextFile(EnterFile,True) OutStream.WriteLine( T ) OutStream.Close 'runs temp file shell.Run ("""" & Enterfile & """") msgbox "This message box will close after " & _ delay & " seconds" & vbcrlf & _ "Your value is " & sString, 64, "Self Closing MsgBox" fso.DeleteFile EnterFile '--------------------------------- End SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU