Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Copy string value to windows clipboard from API 1

Status
Not open for further replies.

fcsuper

Mechanical
Joined
Apr 20, 2006
Messages
2,204
Location
US
Is there a way to copy a string's value within a macro (value entered into an INPUTBOX) to windows clipboard? I'm using SolidWorks 2005 currently. The EditCopy function appears to be what I'm supposed to use, but my API help file is very unclear on how to use it, and I can't get it to work.



Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
 
You would need to use the clipboard functions that are part of either Office or standard VBA, I forget which.
 
Ok, thank you. I can use that, but I still gotta ask: no way to do it directly from a module with an InputBox include of having to use a userform?

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
 
fcsuper,

A suggestion: I would take out all the references to SolidWorks in the References dialog. I no longer have SolidWorks 2005 installed on my computer. The macro would not run until I unchecked Solidworks Utilities 2005 Type Library. This will allow the macro to run with any version of SolidWorks without the user having to figure out or complain to you why the macro will not run.

SA
 
Sure. Just remove the UserForm entirely and change your code to:

Code:
Dim I As Integer
Dim J As Integer
Dim dataStr As String
Dim buildStr As String
Dim tempStr As String
Dim Done As Boolean

''''''''''''''''''
Dim myData As New MSForms.DataObject  'This line was moved from the UserForm code
''''''''''''''''''


Sub main()

    buildStr = ""
    
    dataStr = "Use ALT + Keypad for special characters.  Examples:" + Chr(13)
        dataStr = dataStr + "171 = " + Chr(189) + "      172 = " + Chr(188) + _
        "      241 = " + Chr(177) + Chr(13)
        dataStr = dataStr + "250 = " + Chr(183) + "      253 = " + Chr(178) + _
                      "      248 = " + Chr(186) + Chr(13) + Chr(13)
        dataStr = dataStr + "Choose OK to copy to clipboard." + Chr(13)
    
        
    tempStr = buildStr
    buildStr = InputBox(dataStr, "Editor Special Characters", tempStr)
        
        If buildStr <> "" Then
''''''''''''''''''''''''
             myData.SetText buildStr	'Remove the UserForm reference
             myData.PutInClipboard		'from these two lines
''''''''''''''''''''''''
        End If
    
End Sub

You do still have to include the Microsoft Forms reference, but you don't have to have an actual form in the macro.
 
Thanks guys.

Apparently I've been sold on a fantasy that SolidWorks is supposed to know when to use current libraries instead of past versions. I'm going to go through all of my macros to see where this might bring up an issue. Anyways, new update:


BTW, I'm still working on building my site up, I want to create a site that would've been helpful to me when I first started out making macros and customizing SolidWorks. Comments are welcome, and I will appreciate any public domain or freeware submissions or website links I might be missing (feel free to register on the site).

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
 
Actually, what is the deal with those libraries? Some are essential. Some SolidWorks installations seem to know to use the current version of them, and others do not. I was told before by my VAR that any macro should be useable on any higher version of SolidWorks where libraries are concerned.
Has anyone else run into issues with libraries?

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
 
handleman.

What is the exact name of the MS Forms library?

SA
 
Do you mean the filename of the DLL? It's FM20.dll, most likely located in C:\WINDOWS\system32. In the References dialog it shows up as "Microsoft Forms 2.0 Object Library".
 
handleman,

Thanks, that DLL was not in my references dialog.

SA
 
fcsuper,

Here is another option. Try this macro:


It is based on code written by Bob Bedell that I found at :
My first post with handleman's enhancement is much cleaner in my opinion but, if someone else was like me and did not have the FM20.dll loaded, this will eliminate you having to post solutions to possible problems with the macro not running.

SA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top