Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Print referenced file

Can someone please tell me how I can print a file reference by a hyperlink.
Most of the referenced files are either PDFs or Word documents.
I can get the full file name from the hyperlink but how do I print that file
as if clicking on "Print" on the popup menu in windows explorer. I need to
do this from a macro in Excel.

Thanks for any help,
Fred



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Print referenced file

Put your hyperlink in some cell; I chose C3, then try something like this:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Address = "$C$3" Then ActiveSheet.PrintOut
End Sub

Remember, this is event-ode, so you have to right-click on the tab of the
sheet where you want to run the code. Paste it into the window that opens.

Regards,
Ryan---
--
RyGuy


"Fred" wrote:

Can someone please tell me how I can print a file reference by a hyperlink.
Most of the referenced files are either PDFs or Word documents.
I can get the full file name from the hyperlink but how do I print that file
as if clicking on "Print" on the popup menu in windows explorer. I need to
do this from a macro in Excel.

Thanks for any help,
Fred




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Print referenced file

Thanks Ryan but I want to print the file that the hyperlink references, not
the worksheet.

Fred

"ryguy7272" wrote in message
...
Put your hyperlink in some cell; I chose C3, then try something like this:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Address = "$C$3" Then ActiveSheet.PrintOut
End Sub

Remember, this is event-ode, so you have to right-click on the tab of the
sheet where you want to run the code. Paste it into the window that opens.

Regards,
Ryan---
--
RyGuy


"Fred" wrote:

Can someone please tell me how I can print a file reference by a
hyperlink.
Most of the referenced files are either PDFs or Word documents.
I can get the full file name from the hyperlink but how do I print that
file
as if clicking on "Print" on the popup menu in windows explorer. I need
to
do this from a macro in Excel.

Thanks for any help,
Fred






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Print referenced file

There's a good example here
http://www.vbaccelerator.com/codelib/shell/shellex.htm

towards the bottom you'll see a sample of how to print, change "Me.Hwnd" to
0&, or application.hwnd (in XL10+).

you might want to change
ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_SHOWNORMAL)
to
ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_HIDE)

Regards,
Peter T

"Fred" <leavemealone@home wrote in message
...
Can someone please tell me how I can print a file reference by a
hyperlink. Most of the referenced files are either PDFs or Word documents.
I can get the full file name from the hyperlink but how do I print that
file as if clicking on "Print" on the popup menu in windows explorer. I
need to do this from a macro in Excel.

Thanks for any help,
Fred





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Print referenced file

Thanks Peter.


"Peter T" <peter_t@discussions wrote in message
...
There's a good example here
http://www.vbaccelerator.com/codelib/shell/shellex.htm

towards the bottom you'll see a sample of how to print, change "Me.Hwnd"
to 0&, or application.hwnd (in XL10+).

you might want to change
ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_SHOWNORMAL)
to
ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_HIDE)

Regards,
Peter T

"Fred" <leavemealone@home wrote in message
...
Can someone please tell me how I can print a file reference by a
hyperlink. Most of the referenced files are either PDFs or Word
documents.
I can get the full file name from the hyperlink but how do I print that
file as if clicking on "Print" on the popup menu in windows explorer. I
need to do this from a macro in Excel.

Thanks for any help,
Fred









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Print referenced file

Couple of other things you'll need to adapt in the example for VBA for the
error handling -

Change
dim sErr As Long (that must be a typo)
to
sErr As String

after
Else
' raise an appropriate error:
add
On Error Goto errH

change
Err.Raise lErr, , App.EXEName & ".GShell", sErr
to
Err.Raise lErr, , sErr

just before
End Function
add
Exit Function
errH:
MsgBox sFIle & vbCR & Err.Description

Regards,
Peter T


"Peter T" <peter_t@discussions wrote in message
...
There's a good example here
http://www.vbaccelerator.com/codelib/shell/shellex.htm

towards the bottom you'll see a sample of how to print, change "Me.Hwnd"
to 0&, or application.hwnd (in XL10+).

you might want to change
ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_SHOWNORMAL)
to
ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_HIDE)

Regards,
Peter T



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Print referenced file

Thanks again, with those changes it is working just fine.

"Peter T" <peter_t@discussions wrote in message
...
Couple of other things you'll need to adapt in the example for VBA for the
error handling -

Change
dim sErr As Long (that must be a typo)
to
sErr As String

after
Else
' raise an appropriate error:
add
On Error Goto errH

change
Err.Raise lErr, , App.EXEName & ".GShell", sErr
to
Err.Raise lErr, , sErr

just before
End Function
add
Exit Function
errH:
MsgBox sFIle & vbCR & Err.Description

Regards,
Peter T


"Peter T" <peter_t@discussions wrote in message
...
There's a good example here
http://www.vbaccelerator.com/codelib/shell/shellex.htm

towards the bottom you'll see a sample of how to print, change "Me.Hwnd"
to 0&, or application.hwnd (in XL10+).

you might want to change
ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_SHOWNORMAL)
to
ShellExecuteForExplore(Owner, sOperation, sFIle, 0, 0, essSW_HIDE)

Regards,
Peter T





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Xla file being referenced in the cell Sandeep Excel Discussion (Misc queries) 3 July 11th 07 11:44 AM
Referenced File Shawn Excel Programming 2 September 12th 06 04:07 AM
Getting value from an unopened file (indirectly referenced) learnexcel Excel Programming 11 July 27th 05 01:36 AM
referenced file shawn Excel Programming 1 September 26th 04 04:55 PM
Changing the name of a referenced file Colleen[_2_] Excel Programming 1 December 12th 03 06:54 PM


All times are GMT +1. The time now is 08:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"