×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Macro to copy Filename to clipboard

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

RE: Macro to copy Filename to clipboard

Hi,

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 Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources