Marco/Hyperlink

  • Thread starter Marco/Hyperlink Function
  • Start date
M

Marco/Hyperlink Function

Is there a way to make a Marco a hyperlink or button within a document in
Micosoft Word?

Or a hyperlink to follow a menu command.

My goal is to have a option (like a hyperlink or marco) within my document
to print only the page I am on in my document. For example, if someone one
wanted to print Section J, which my be several pages, there would be a
hyperlink function that would print only that scetion.
 
S

Suzanne S. Barnhill

What you describe could be accomplished by a MacroButton field, but you
would still need to write the macro.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Marco/Hyperlink Function" <Marco/Hyperlink
(e-mail address removed)> wrote in message
news:[email protected]...
 
G

Graham Mayor

You can have a *macro* attached to a toolbar button which will print the
current page, or which will print the current section. Sections in Word are
numbered rather than lettered, so what is it that you mean by Section J in
this context?

The following macro will print either the current page, the current section
or the whole document

Sub Print_Choice()
Dim sChoice As Integer
Dim sCurPage As String
Dim sCurSection As String
Dim oRng As Range

sCurPage = Selection.Information(wdActiveEndPageNumber)
sCurSection = Selection.Information(wdActiveEndSectionNumber)

On Error Resume Next
sChoice = InputBox("Print the current page or Section" & vbCr & _
"Enter 1 or 2 as appropriate" & vbCr & _
"1. Print current page only" & vbCr & _
"2. Print current section" & vbCr & _
"3. Print whole document", "Print", 1)
Select Case sChoice
Case Is = 1
ActiveDocument.PrintOut Range:=wdPrintCurrentPage
Case Is = 2
Set oRng = ActiveDocument.Sections(sCurSection).Range
oRng.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Item:= _
wdPrintDocumentContent, Pages:=""
Case Is = 3
ActiveDocument.PrintOut
Case Else
End Select
End Sub

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

Marco/Hyperlink Function

Thank you!
I want to make sure I understand this. First I have to make a marco that
will print. Then using Visual Basic Editor or Microsoft Script Editor I use
the code below, is that right?
Will this allow me to place a button into the document for example, a button
that says click here to print or will it just work when the command is played?
 
J

Jay Freedman

Your questions indicate that you do not understand what Graham told you.

First read the web page http://www.gmayor.com/installing_macro.htm that Graham
provided in his response. That will explain how to use the Visual Basic editor
(*not* the Script editor!) to install the macro into your Normal.dot template.

After the macro has been installed, follow the instructions in
http://www.word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm to
create a button on a toolbar (*not* in the document itself) that will run the
macro when you click the button.

If you want the macro and its button to be contained within the document (for
instance, to let you send the document by email to another computer), there is a
problem. Although you can create a macrobutton field
(http://www.word.mvps.org/FAQs/TblsFldsFms/UsingMacroButton.htm) in the
document, storing a macro in a document instead of in a template causes Word to
assume the macro is a virus. It becomes very complicated to explain to users how
to enable the macro -- enough so to make it impractical.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
M

Marco/Hyperlink Function

THANKS!!!!

The code works great and the toolbar meun as well.
Is there a way the code could modified to print more than one section at a
time. For example, instead of printing only the current section, but to allow
the user to enter in which sections they want to print, like section 2 and 5
only.
 
J

Jay Freedman

It's possible, but I think there's no point to it. The function is already
provided in the Print dialog. In the box where you can type page numbers to
print, type the letter s followed by a section number. Multiple sections can
be separated by commas. For example, to print sections 2 and 5, enter

s2,s5

Read http://www.word.mvps.org/FAQs/Formatting/PrintMultipleSections.htm for
more info.

The macro you already have is somewhat useful because the Print dialog
doesn't have a "current section" option (although there is a "current page"
option).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
M

Marco/Hyperlink Function

Thanks. Since thats something I would like the marco to do, is there a link
or some time of guide that would help me come up with the code to do that?
 
G

Graham Mayor

Extending the original macro a little further, without knowing how many
sections your document contains or whether the sections in that document are
full pages or parts of pages and which of the sections you wish to print
sets a few problems, but the following allows you to select the sections,
one at a time and it will print them individually whether they are full page
or not and keeps offering to print more sections until either all the
sections are printed or you cancel, but it isn't the most elegant of macros.


Sub Print_Choice()
Dim sChoice As Integer
Dim sCurPage As String
Dim sCurSection As String
Dim sSection As String
Dim sPrintCount As Integer
Dim oRng As Range

sCurPage = Selection.Information(wdActiveEndPageNumber)
sCurSection = Selection.Information(wdActiveEndSectionNumber)

On Error Resume Next
sChoice = InputBox("Print the current page or Section" & vbCr & _
"Enter 1 to 4 as appropriate" & vbCr & _
"1. Print current page only" & vbCr & _
"2. Print current section" & vbCr & _
"3. Print choice of sections" & vbCr & _
"4. Print whole document", "Print", 1)
Select Case sChoice
Case Is = 1
ActiveDocument.PrintOut Range:=wdPrintCurrentPage
Case Is = 2
Set oRng = ActiveDocument.Sections(sCurSection).Range
oRng.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Item:= _
wdPrintDocumentContent, Pages:=""
Case Is = 3
sSection = InputBox("This document contains " & _
ActiveDocument.Sections.Count & " sections" & vbCr & _
"Enter the number of the first section you wish to print", _
"Print", 1)
If sSection <> "" Then
Set oRng = ActiveDocument.Sections(sSection).Range
oRng.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Item:=
_
wdPrintDocumentContent, Pages:=""
PrintCount = 1
GoAgain:
If ActiveDocument.Sections.Count > 1 Then
sSection = InputBox("Print another section?" & vbCr
& _
"Enter the number of the next section you wish to
print", _
"Print")
If sSection > "" Then
Set oRng =
ActiveDocument.Sections(sSection).Range
oRng.Select
ActiveDocument.PrintOut Range:=wdPrintSelection,
Item:= _
wdPrintDocumentContent, Pages:=""
PrintCount = PrintCount + 1
If PrintCount < ActiveDocument.Sections.Count
Then
GoTo GoAgain
End If
End If
End If
End If
Case Is = 4
ActiveDocument.PrintOut
Case Else
End Select
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

Marco/Hyperlink Function

Thank you.
There is a 'Complie error; Syntax error' which will not allow the macro to
run.
 
M

Marco/Hyperlink Function

Thank you Graham the code works great.
I'm not a Microsoft Visual Basic user and I was wondering for the 'print
choice of section' option could i enter more then one section so it would
only need one pop-up then end. For example, the user could enter in 1,5,9 and
only those sections would print out and the program would end. I was also
wondering if there was a way that letters could be enter in instead of
numbers and print out the corresponding sections.
 
G

Graham Mayor

You could do that, but this would create a problem if your sections were
less than a page, as printing by section prints whole pages. The method I
have used prints selected text, the text selected and printed individually
by section, and thus prints only the section content regardless of whether
it is only part of a page. If you want to print Sections 1, 5 & 9 full
pages, then you might as well forget the macro and use the print dialog as
Jay suggested earlier. There is no point re-inventing the wheel.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top