Microsoft Office Forums Word 2010 VBA Print Macro - Specified Sections

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2017, 01:05 PM
Benbon Benbon is offline Word 2010 VBA Print Macro - Specified Sections Windows 7 64bit Word 2010 VBA Print Macro - Specified Sections Office 2010 64bit
Novice
Word 2010 VBA Print Macro - Specified Sections
 
Join Date: Mar 2017
Posts: 2
Benbon is on a distinguished road
Default Word 2010 VBA Print Macro - Specified Sections

Hello Everyone,

I would like start off by saying that it's nice to meet you all. My name is Benbon and I'm a motivated individual who just started learning Visual Basic last week. I'm working hard to study and research the fundamentals of VBA; however, it has been challenging.

I have a manual that I'm attempting to create a print macro for. The manual is very large. Each section is formatted by title and section number (4.1 title 1, 4.2 title 2, 5.0 title 3, etc.). The majority of the manual has generalized information; however, there are several sections that are state specific. The goal is to create a macro that allows the user to choose their state from the drop down box so when they print, it only prints the general information along with the state specific section.



I have managed to create a form with a functional drop down that lists each state, along with the control buttons of 'Ok' and 'Cancel'. The challenge is that the manual is updated on a monthly basis. Due to this, I can't use page number ranges. I need this to be dynamic so it will scale as information is added. I'm guessing this can be done by using the sections as ranges. I have been searching goggle for several days and haven't been able to find information specific to this. Any recommendations are much appreciated.
Reply With Quote
  #2  
Old 03-28-2017, 04:45 PM
macropod's Avatar
macropod macropod is offline Word 2010 VBA Print Macro - Specified Sections Windows 7 64bit Word 2010 VBA Print Macro - Specified Sections Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,648
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

To print specified Sections, simply supply the Section #s to the print dialogue, prefixed by 's'. For example, to print Sections 1, 2, 4, 5, 6, 7 & 9, you might input "s1-s2,s4-s7,s9" in the print dialogue, thus:
Code:
With Dialogs(wdDialogFilePrint)
  .Background = True
  .Pages = "s1-s2,s4-s7,s9"
  .Execute
End With
to print the document without even displaying the dialogue.

For further info on printing nominated ranges across Sections, see: https://support.microsoft.com/en-au/...d-in-word-2003
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 03-30-2017, 12:55 PM
Benbon Benbon is offline Word 2010 VBA Print Macro - Specified Sections Windows 7 64bit Word 2010 VBA Print Macro - Specified Sections Office 2010 64bit
Novice
Word 2010 VBA Print Macro - Specified Sections
 
Join Date: Mar 2017
Posts: 2
Benbon is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
To print specified Sections, simply supply the Section #s to the print dialogue, prefixed by 's'. For example, to print Sections 1, 2, 4, 5, 6, 7 & 9, you might input "s1-s2,s4-s7,s9" in the print dialogue, thus:
Code:
With Dialogs(wdDialogFilePrint)
  .Background = True
  .Pages = "s1-s2,s4-s7,s9"
  .Execute
End With
to print the document without even displaying the dialogue.

For further info on printing nominated ranges across Sections, see: https://support.microsoft.com/en-au/...d-in-word-2003
Thank you for your response. I did try the code that was provided and for some reason, it did not recognize the sections. Instead, it would attempt to print the entire document. Also, there are many sections in this manual. I'm looking for a way to group them together. Here's an example: Sections 1 and 2 are always needed no matter what selection is made. Section 3 can be left out of printing entirely, and then section 4 through 4.4 is needed. Section 4.5 contains the specific information where the user will be selecting their state. It's broken down as 4.5.1 CA, 4.5.2 TX, 4.5.3 FL and so on. So essentially, if the user selects 'CA' from my drop down form, the code would initialize printing of Sections 1-2, 4-4.4, and 4.5.1.

I believe the code should be written on the frm under the cmdok; however, I'm not sure as I was unable to get it to run. I have backed out the additional code that I was tinkering with (since it was not working) and brought it back to basics. I have also removed the majority of the states to shorten the code for posting here. I'm really trying to figure out where to go from here and having a tough time. I've been researching VBA each day and on the weekends but clearly I have a long way to go. I apologize upfront for my lack of skill with this software. Here is what I have:

modMain:

Sub CallUF()
Dim oFrm As frmSites
Set oFrm = New frmSites
oFrm.Show
Unload oFrm
Set oFrm = Nothing
lbl_Exit:
Exit Sub
End Sub
Sub PrintOut()
With Dialogs(wdDialogFilePrint)
.Background = True
.Pages = "s1-s2, s4-s5"
.Execute
End With
End Sub

frmSites:

Option Explicit
Private Sub cmdCancel_Click()
Me.Hide
End Sub
Private Sub cmdOK_Click()
Me.Hide
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Atlanta, GA"
.AddItem "Bethesda, MD"
End With
lbl_Exit:
Exit Sub
End Sub
Reply With Quote
  #4  
Old 03-30-2017, 02:31 PM
macropod's Avatar
macropod macropod is offline Word 2010 VBA Print Macro - Specified Sections Windows 7 64bit Word 2010 VBA Print Macro - Specified Sections Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,648
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Quote:
Originally Posted by Benbon View Post
Thank you for your response. I did try the code that was provided and for some reason, it did not recognize the sections. Instead, it would attempt to print the entire document. Also, there are many sections in this manual. I'm looking for a way to group them together. Here's an example: Sections 1 and 2 are always needed no matter what selection is made. Section 3 can be left out of printing entirely, and then section 4 through 4.4 is needed. Section 4.5 contains the specific information where the user will be selecting their state. It's broken down as 4.5.1 CA, 4.5.2 TX, 4.5.3 FL and so on. So essentially, if the user selects 'CA' from my drop down form, the code would initialize printing of Sections 1-2, 4-4.4, and 4.5.1.
Sections in Word are defined by Section breaks, inserted via Page Layout>Breaks>Section Breaks, not by paragraph numbering. Hence, in Word parlance, there can be no such thing as Sections numbered 4.4, 4.5.1, etc.

See: https://support.office.com/en-us/art...7-E503BDF8375C
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2010 VBA Print Macro - Specified Sections Large Word doc duplicating large sections when I print it. Kea Word 3 05-30-2015 02:28 PM
Word 2010 VBA Print Macro - Specified Sections Macro to print "Current Page" in Word 2010 Jshopping Word VBA 10 06-08-2012 01:15 AM
Word 2010 VBA Print Macro - Specified Sections Word Macro That Checks a Check Box Form Field When File Print is Executed DKerne Word VBA 4 06-09-2011 11:54 AM
Print Macro in MS Word steve207 Word VBA 0 09-10-2010 02:11 AM
Macro to export document sections to individual txt files? MJMR999 Excel Programming 0 02-18-2010 12:49 PM


All times are GMT -7. The time now is 08:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft