Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to copy Filename to clipboard

Status
Not open for further replies.

rickyt

Automotive
Jun 26, 2002
233
US
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
 
Replies continue below

Recommended for you

Hi,

You can do it very simple in vba but not in CATScript or catvbs...

Now, you can use workaround... example in catvbs

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

'---------------------------------
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 Sub


Regards
Fernando

- Romania
- EU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top