Consulting

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 21 to 40 of 54

Thread: VBA range

  1. #21
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    What I meant is that the overall pages concept can be tricky when you are dealing with multiple sections. If the sections are defined to restart the number at page 1, then you're going to have to do trial and error to figure out how to print page 5 of section 2, when it's actually the 7th page of the document. Printing a specific page from the print dialog box is (if I recall correctly) always the absolute page of a document, not the relative page of a section.
    So without sample documents, we can only give you the tools to be able to try and solve this on your own specific environment with your own specific documents. That is why this thread has so many responses. Because the answer is not always the same for all scenarios.

    That's why any time someone asked questions related to pages, they get training on how to find the answer themselves, rather than just answers.

    Does thy make sense, Zack?

  2. #22
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Oh my yes, if you are dealing with multiple sections; or sections with renumbering, there are many issues.

    Yes a specific page in the print dialog is absolute.

    Unless stated otherwise it appears that Zack's document does not deal with multiple sections, just the one - Section 2.

  3. #23
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    http://support.microsoft.com/kb/826218

    "How to print a range of pages in a multiple-section document in Word 2010, in Word 2007, and in Word 2003"


    Both the online help and the MS KB say that "p2s2-p3s2" should print pages 2 and 3 of section 2, but the recorded macro and the manual version do not seem to work.

    The Printer Queue flashes for a second but nothing comes out

    [vba]
    Sub Macro2()
    Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
    wdPrintDocumentWithMarkup, Copies:=1, Pages:="p2s2-p3s2", PageType:= _
    wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
    PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
    PrintZoomPaperHeight:=0
    End Sub
    [/vba]

    Paul

  4. #24
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    And Section renumbers at 1? And there is a page 2 and 3?

  5. #25
    Quote Originally Posted by fumei
    Oh my yes, if you are dealing with multiple sections; or sections with renumbering, there are many issues.

    Yes a specific page in the print dialog is absolute.

    Unless stated otherwise it appears that Zack's document does not deal with multiple sections, just the one - Section 2.
    Exactly, just one section..

    Absolute print dialog is what I need. It's strange no one ever asked for something similar..

    What chance do I have of creating it if Frosty found difficulties with it..?

  6. #26
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by fumei
    And Section renumbers at 1? And there is a page 2 and 3?
    MS KB -- Printing pages in relation to their section depends on how the numbering is formatted. If the numbering in the document is set as continuous, referencing page 1 of a particular section most likely does not result in anything being printed. This occurs because, when the numbering is formatted as continuous, the page numbers in all sections except the first do not start with page 1. In this case, the page would have to be referenced according to its overall position in the documents page collection.
    I'm not sure how the OP's document is numbered, but when I re-start page numbering at 1 for a section, the P2S2-P4S2 print range works as expected

    So formatting the string for .Pages based on an user's Input as others have suggested might be made to work if section 2 starts renumbering at 1:

    P20S2-P25S2

    Otherwise if not, I'd think that "P20-P25" would work even if 20-25 are in a different section (based on the MS KB)


    Paul
    Attached Files Attached Files

  7. #27
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "What chance do I have of creating it if Frosty found difficulties with it..?"

    Ummm, Frosty did not find difficulties with it. And, as stated, it is not that difficult if you are dealing with one section, and no renumbering.

    Have you actually tried getting a string variable (never mind the inputbox for now) used in the Pages parameter?

  8. #28
    Quote Originally Posted by fumei
    "What chance do I have of creating it if Frosty found difficulties with it..?"

    And, as stated, it is not that difficult if you are dealing with one section, and no renumbering.

    Have you actually tried getting a string variable (never mind the inputbox for now) used in the Pages parameter?
    Do you have an example of a similar string variable?

  9. #29
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    For heavens sake, I have suggested you to look at Help for Inputbox on how to get and use a string variable.

    I am done here. You are not even trying. One last time...

    Declare a string variable by using Dim.
    Give it a value by using variable = value (in quotation marks)
    Pages:= variable.

    I am done. Good luck.

  10. #30
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    How to achieve printing of the particular selection of pages (25-30 for example) with the macro combined with the msgbox prompting for the desired page range?
    Zack - Just a question for clarification

    In your original post, you asked about a 'selection', not 'section'

    In Word, both terms have specific meanings which not be the 'everyday' ones

    Are you looking to have the user enter a start and end page number and then just print that?

    As you can tell, printing can be tricky, and just the Start/End could be made to work for a simply structured document, but for a multi-section document document with a variety of page (re)numbering, it's not that simple.

    Paul

  11. #31
    Quote Originally Posted by Paul_Hossler
    Are you looking to have the user enter a start and end page number and then just print that?
    That's right. Just to enter a start and an end page number. No sections.

  12. #32
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I will ask again. Have you actually tried putting in "20-25" into Pages? Does it work?

    If it does, try it again using a string variable = "20-25". Does it work?

  13. #33
    Quote Originally Posted by fumei
    I will ask again. Have you actually tried putting in "20-25" into Pages? Does it work?

    If it does, try it again using a string variable = "20-25". Does it work?
    [VBA]Dim "20-25" As String[/VBA]


    Like this?

  14. #34
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Zack, this almost seems like trolling.

    Forget VBA. There are books you can get on the subject. You want to print a range of pages. I repeat-- forget VBA.

    In the File > Print dialog (same thing you did to record a macro to print page 5)... can you simply print pages 5-6?

    If you can-- then record a macro and do it again. Compare that recored macro to the macro you recorded to print *only* page 5.

    That is the only task you should do, at the moment, if all you want to do is be able to print a range of pages.

    If you can post that code, and see the difference between the macro which prints page 5, and the macro which prints pages 5 and 6 of your document... then we're getting somewhere.

    But stop throwing things against the wall with your posts in such a random fashion. You won't be a programmer at the end of this thread. But you *should* have a better ability to solve your own Word problems.

  15. #35
    Quote Originally Posted by Frosty
    That is the only task you should do, at the moment, if all you want to do is be able to print a range of pages.
    I am trying to use Dim as suggested. I don't know if I did it right..or how should I do it..

  16. #36
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Example:

    [vba]Sub Simple()
    'This is a string variable declared using the "Dim" statement.
    Dim strDemo As String
    'This defines the string value.
    strDemo = "If you are going to post claiming what you tried, then post what you tried." & vbCr + vbCr
    'This employs the variable string in a Msgbox function
    If MsgBox(strDemo & "Can you do that please?", vbQuestion + vbYesNo, "Help Us Help You!") = vbYes Then
    MsgBox "Thank you."
    Else
    MsgBox "Like Fumei, I'm done and should never have started." & vbCr + vbCr _
    & "You should find another forum to troll.", vbInformation + vbOKOnly, "STOP TROLLING"
    End If
    End Sub[/vba]
    Greg

    Visit my website: http://gregmaxey.com

  17. #37
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    1. In the VBA editor, under Help, searching for 'Dim' brings up an explaination and examples:

    Remarks
    Variables declared with Dim at the module level are available to all procedures within the module. At the procedure level, variables are available only within the procedure.
    Use the Dim statement at module or procedure level to declare the data type of a variable. For example, the following statement declares a variable as an Integer.
    Dim NumberOfEmployees As Integer

    2. Likewise in Help, there are examples of how to use the 'Inputbox function'

    3. If you don't have a [Developer] tab where you can record macros, then go to Word Options, and check 'Show Developer tab on the Ribbon" (assuming you're using 2007/2010)

    4. As others have suggested, record a small macro to just print some pages to see the code generated by Word.

    5. Edit the recorded code to incorporate information from the Dim and the Inputbox help examples.

    Paul

  18. #38
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Greg has provided an excellent example.

    You will need to do the work from here on, rather than simply trying whatever it is you think you should try, responding to whatever you want to respond to, rather than actually trying to solve your problem.

    The problem is not how we communicate... the problem is your lack of desire to try and solve your problem the way we are trying to solve your problem.

    You have everything you need to solve your original problem. It is up to you now.

    I won't reply unless you do the following:
    1. Attempt to print pages 5-6 manually, and then post the recorded macro of that attempt.
    2. Attempt to utilize greg's macro combined with the usage of an InputBox in the earlier posts, and get that macro to show a message box of the same string you get from your post on #1.

    If you authentically try to solve your own problems-- you will get an enormous amount of help from this forum.

    If you are unwilling to do that, or are simply trolling to see how many regular posters you can get to try and tell you exactly the same thing... then you will get zero help from this forum. There are only 5-6 regular posters. If you alienate all of them, you might as well start with a new user name and try again.

  19. #39
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "I am trying to use Dim as suggested. I don't know if I did it right..or how should I do it.."

    This is a flat out untruth. no one suggested it like that. What I very much DID suggest was to look at Inputbox in Help to see how variables are declared and used. Or, as was also suggested look up Dim in Help. There is NO example that uses Dim like that. You are being useless in making any effort. It would take a minimum of effort to determine how to use Dim.

    Either trolling or a blind inability to do anything at all.
    Last edited by fumei; 09-17-2012 at 03:10 PM.

  20. #40
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Or...hmmmmm, could the reasons that can not be discussed be a school assignment??? In any case Zack, congratulations, you have successfully annoyed all the top posters in the forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •