Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Open PDF / save value to Clipboard

Status
Not open for further replies.

pewill

Industrial
Mar 4, 2010
4
0
0
CH
Hi,

I have searched a lot for let my macro (swp in Solidworks) do two things:

1) opening a PDF in AcrobatReader after creating this PDF out of SW;
2) save a value to the windows clipboard

how can i do this?

regards, Peter
 
Replies continue below

Recommended for you

Not very pretty, and I don't know if it would be very reliable (or even work)... but once open maybe you could activate the PDF and do a SendKeys to accomplish Select All (either [Ctrl]+A or [Alt]+E+L), then Copy, you can then iterate thru the Clipboard Contents...maybe?
 
In Visual Basic:
"1) opening a PDF in AcrobatReader after creating this PDF out of SW;"
After saving the PDF you can use the API call ShellExecute

"2) save a value to the windows clipboard"
Clipboard.Clear
clipboard.settext "YourStringvalue"


Using ShellExecute
'Declare it
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal _
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As _
Long

'call it
ShellExecute Me.hwnd, "open", "yourpdffile.pdf", vbNullString, vbNullString, SW_SHOW

Francis
 
Dim objData As New MSForms.DataObject
objData.SetText "Hello World!"
objData.PutInClipboard

objData.GetFromClipboard
Debug.Print objData.GetText
 
Thanks for the support. The copy to clipboard statement is working, but after installing the 'Microsoft Forms 2.0 Object Library' This was missing in my VB references.

But how do i put the shell execute into my swp-macro? As a function, or in the Sub Main() ? And wich VB library does it need?

regards Peter

see also attached swp macro.

 
 http://files.engineering.com/getfile.aspx?folder=33b2f8d5-e652-4d3f-abf4-f16793a5da12&file=ZGN-SafeAsPDF.swp
I found this method somewhere...

Code:
Option Explicit
 
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal Hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
 
Sub Open_Pdf()
Dim PdfFile As String
Dim FDir As String
 
PdfFile = "ooslist.pdf" 'Pdf file name
FDir = "D:\HS" 'Directory where Pdf file exists
 
ShellExecute 0, "Open", PdfFile, "", FDir, 1
End Sub

 
Status
Not open for further replies.
Back
Top