#1
|
|||
|
|||
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. |
#2
|
||||
|
||||
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 For further info on printing nominated ranges across Sections, see: https://support.microsoft.com/en-au/...d-in-word-2003
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Quote:
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 |
#4
|
||||
|
||||
Quote:
See: https://support.office.com/en-us/art...7-E503BDF8375C
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Large Word doc duplicating large sections when I print it. | Kea | Word | 3 | 05-30-2015 02:28 PM |
Macro to print "Current Page" in Word 2010 | Jshopping | Word VBA | 10 | 06-08-2012 01:15 AM |
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 |