Consulting

Page 2 of 4 FirstFirst 1 2 3 4 LastLast
Results 21 to 40 of 79

Thread: Printing macro - impossible?

  1. #21
    Quote Originally Posted by fumei
    Well...it does not. Why would it? You have NEVER mentioned anything AT ALL about a header. Please try to stick with what you actually ask.

    I fear you do not understand how headers work either. If any page has a different header they MUST be separated by a Section break. If you are now asking - out of the blue - for something to add a Section break then yes, fields will not work. You would need VBA to add the Section break.

    OR, just do it yourself. If you are not going to show some evidence that you are actually trying to do something yourself, it may be best if you just do what you want manually.

    I am not even sure what you mean by "pre-defined header". I am assuming what you mean is that there IS a header - which has nothing pre-defined about it.
    Well, if you number pages then you will have 50 pages and the next one will be 51'st. But if you want a standalone document to be printed as it's 51'st (and that document has one page) you don't want it to have a number 51 in header.

    Evidence I've shown was clearly enough for macropod to give me the field code. What other evidence would you have me posted?

    Pre-defined means when you define (your firm for example) how the header should look like for the each document printed.

    You said I would need a VBA code. Is it so long and hard to write? This is VBA express forum after all.

  2. #22
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Post an example of what you have done with your first try using a field code. That would be evidence. Other than that, you are just posting words.
    Well, if you number pages then you will have 50 pages and the next one will be 51'st. But if you want a standalone document to be printed as it's 51'st (and that document has one page) you don't want it to have a number 51 in header.
    Very true. What is also true is that - as I stated - you must make a new Section break.

    What is also true is that you never mentioned anything about a change in header before.
    Evidence I've shown was clearly enough for macropod to give me the field code. What other evidence would you have me posted?
    You gave no evidence. You gave a request, a question. And macropod gave you an effective answer to your question...which you have not tried to do. Or so it seems, as there is no eveidence - a posted sample document showing what you did for example - that you have done anything.

    A header is a header, it is the contents of a header. It is what you put there. There is nothing pre-defined about it.

    Here is what you need to do. While it is possible to have an INCLUDETEXT field in the first document, and ADD a Section break before it, the easiest route IMO is to use VBA to:
    1. go to the end of the document
    2. add a Section break
    3. bring in the other document as an insert file.
    [vba] .EndKey Unit:=wdStorywith
    .InsertBreak Type:=wdSectionBreakNextPage
    .InsertFile FileName:="Other.doc", Range:=""
    end with
    [/vba]This will NOT - repeat NOT - change the header. In fact, the new Section will have the same header. I am not going to show you how to do that (change the header), because you did not ask for that.

  3. #23
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    BTW: how is it going with your original issue, printing single then duplex? As stated by your need, I think you will need to do two separate print jobs.

  4. #24
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    With all due respect, Gerry, all Zack really needs is to have is a 'Next Page' Section break between the IF field and the INCLUDETEXT field, with the document's new last Section's header & footer unlinked from those of the previous Section. No vba is needed for this - it's all basic document management. In any event (as you yourself observe), your code does nothing to address the header & footer issue.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #25
    Quote Originally Posted by fumei
    I am not going to show you how to do that (change the header), because you did not ask for that.
    I thought I mentioned before that I needed to keep the header of the inserted document (blank), but perhaps I am wrong. You are right, you don't have to show it to me how it's done because I wasn't specific about what I need and even though there were some indications, those probably weren't precise enough, so I understand you completely.

    [VBA]

    Selection.InsertBreak Type:=wdSectionBreakNextPage
    Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8", FileName _
    := _
    "C:\documents\document1.doc" _
    , LinkToFile:=True, DisplayAsIcon:=False[/VBA]

    This is what very loosely gets the job done, though it does not scroll down the document to the last paragraph of it's last page automatically.

    I tried your VBA code and it says: "Compile error. Invalid or unqualified reference".

  6. #26
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Zack,

    I think what you're kind of missing here is that you can attach actual documents to posts after you get 5 posts. It would probably be a good idea to post a dummy document, with your attempts to set it up the way it would work on your system... and then everyone would be looking at the same thing.

    And while some settings wouldn't work (i.e., printer-specific settings like duplex), you could still have multiple people looking at the document you are attempting to print, with the field codes in it, and then describe what isn't working.

    Other than that, it's all (as you said earlier) a little too conceptual and esoteric. Otherwise, I think you may need to hire someone.

    VBA solutions (despite this being a VBA forum) are not always (and often not) the best solution. VBA solutions are typically (in my experience) thought to be "best" when the person requesting that solution doesn't understand all of the built-in capabilities of Word. In short, training often substitutes better than a one-off coding solution.

    Can you try to dummy up a document and post it? That will probably get you closer to your desired solution than a lot more posts back and forth.

  7. #27
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I tried your VBA code and it says: "Compile error. Invalid or unqualified reference".
    True. I missed the opening With.[vba]
    With Selection
    .EndKey Unit:=wdStorywith
    .InsertBreak Type:=wdSectionBreakNextPage
    .InsertFile FileName:="Other.doc", Range:=""
    End With [/vba]The .EndKey instruction moves the document down to the end, which is where you want the Section break.

    Paul,
    With all due respect, Gerry, all Zack really needs is to have is a 'Next Page' Section break between the IF field and the INCLUDETEXT field
    Yes, which is what I have been saying. He needs a Section break. And it has to be either:

    a) before the INCLUDETEXT field is put in; OR
    b) before the file is inserted.

    If the operation is a one-off print job, then inserting the file, printing, then close without a save will do it.

    If the operation is to be a permanent change (keeping the other document included), then using an INCLUDETEXT is the way to go.

  8. #28
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    BTW: Why are you using an OLE object?????[vba]Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8", FileName _
    := _
    "C:\documents\document1.doc" _
    , LinkToFile:=True, DisplayAsIcon:=False [/vba]

  9. #29
    Quote Originally Posted by Frosty
    VBA solutions are typically (in my experience) thought to be "best" when the person requesting that solution doesn't understand all of the built-in capabilities of Word. In short, training often substitutes better than a one-off coding solution.
    I admit, I do not comprehend all of the Word's built in features, thus my question posted here in this forum. I sought for a solution that would resolve the problem at hand and found myself here asking for an advice from people more knowledgeable than myself. If nothing, than in the field of the MS Word/VBA. I am thankful for the training I received so far and I verily learnt a lot already. Henceforth I will try to find a way to automatically get to the last paragraph of the document's last page. This should greatly aid me in my efforts of finding the solution for the complete code that I require.

  10. #30
    Quote Originally Posted by fumei
    True. I missed the opening With.[vba]
    With Selection
    .EndKey Unit:=wdStorywith
    .InsertBreak Type:=wdSectionBreakNextPage
    .InsertFile FileName:="Other.doc", Range:=""
    End With [/vba]
    Run-time error '4120'

    Debug "yellows" [VBA].EndKey Unit:=wdStorywith[/VBA]

  11. #31
    Quote Originally Posted by fumei
    BTW: Why are you using an OLE object?????[vba]Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8", FileName _
    := _
    "C:\documents\document1.doc" _
    , LinkToFile:=True, DisplayAsIcon:=False [/vba]
    My knowledge about VBA or Word 2003 is really limited. This is all I could find that could loosely accomplish what I had in mind, a part of it at least.

  12. #32
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Zack, you should try recording macros that do what you want to do... even though that won't often be the "best" end product, it is a good Rosetta stone for initially learning VBA. That does, however, require understanding what you want to do and then doing it.

    Even if someone posts code which doesn't work, but explains how it should work... you'll skip over some of the "typo" kinds of stuff.

    the .EndKey Unit:=wdStory is what you're looking for... the "with" tag was a typo by Fumei.

    On some of the simplest stuff, I would guess that some of us (myself included) often just type the code, rather than test it in VBA.

    I still think you should work up a dummy document, with your attempt to use the fields indicated in the other posts, and then post that document (as well as the document you're trying to include), and then describe why that doesn't work.

  13. #33
    Quote Originally Posted by Frosty
    Zack, you should try recording macros that do what you want to do... even though that won't often be the "best" end product, it is a good Rosetta stone for initially learning VBA. That does, however, require understanding what you want to do and then doing it.

    Even if someone posts code which doesn't work, but explains how it should work... you'll skip over some of the "typo" kinds of stuff.

    the .EndKey Unit:=wdStory is what you're looking for... the "with" tag was a typo by Fumei.

    On some of the simplest stuff, I would guess that some of us (myself included) often just type the code, rather than test it in VBA.
    That's exactly how I got to the OLE object in the first place. I got it while recording a macro.

    Thank you for correcting Fumei's code, it works good now.

  14. #34
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Not only a typo, but I did not look very well at what I posted (my bad).

    Zack, I am curious about you tecording the macro that got you the OLE object. WHAT on earth did you do? Especially when I posted the InsertFile instruction. Did you not look at the code?

    Oh. wait a second. Ok. OK. I see how you got there, but could you not see that it was significantly different from what I posted? It is still a little odd to do it that way though..

    BTW: the stupid typo. I have this new laptop and it does the darndest things. It seems to jump the cursor around on its own. In a browser it closes, opens links apparently on its own. Hate it. I can be typing and all of the line. a sudden it jumps to start of

    Like that.....(I kept that one)

    Yes, record macros. Be VERY clear about what you want, and what you ask for.

  15. #35
    Quote Originally Posted by fumei
    Not only a typo, but I did not look very well at what I posted (my bad).
    Doesn't matter. As long as it works now. I should have seen it myself, but I still have difficulties with understanding the VBA, though I try.

    Btw, I went to Insert - object - create from file and clicked "link to file".

    Of course, your macro is a lot better because it automatically gets me down to the bottom of the document.

    Now, is there a way to print that page (the inserted one) and the page before Only, with selecting a specific printer in the process such as
    [VBA]ActivePrinter = "Printer1"[/VBA] for example?

    [VBA]With Selection
    .EndKey Unit:=wdStory
    .InsertBreak Type:=wdSectionBreakNextPage
    .InsertFile FileName:="Other.doc", Range:=""

    ActivePrinter = "Printer1"

    'then the rest

    End With [/VBA]

    Something that could be incorporated within this same macro. I can't tell him to print the pages 50-51, because the document can have 30, 40, 45 or 55 pages, it isn't always the same. I don't know how to tell him to print the inserted document (in my case 1 page only) together with the page that preceded it.

  16. #36
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    1. Get the number of pages in the document (with the added included document)

    2. print all the pages for that number - 1 using single printing

    3. change the printer if needed; change to duplex

    4. print the last two pages.

    Basic logic really.

  17. #37
    Quote Originally Posted by fumei
    1. Get the number of pages in the document (with the added included document)

    2. print all the pages for that number - 1 using single printing

    3. change the printer if needed; change to duplex

    4. print the last two pages.

    Basic logic really.
    So there is no way that there is a command to print the inserted document, that we've discussed before, together with the page that preceded it, regardless of the overall number of the document's pages?

    Something like:"If you run this macro, I will print the inserted document of macro together with the previous page." It is then something that could be used in all situations.

  18. #38
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    So there is no way that there is a command to print the inserted document, that we've discussed before, together with the page that preceded it, regardless of the overall number of the document's pages?

    Something like:"If you run this macro, I will print the inserted document of macro together with the previous page."
    Huh? Of course there is. That is EXACTLY what I posted!

    Print job #1 - print everyting up to the last two pages REGARDLESS of the number of pages (number of pages - 1).

    Print job #2 - the inserted document, together with the page that preceded it, REGARDLESS of the overall number of pages

    Please try to read posts carefully. Again, have you even tried anything yet?

    You have been given a variety of possible ways to go. macropod's INCLUDETEXT and IF statements. Have you actually tried anything? My straight VBA, adding the Section break, insert file, and printing. Have you tried anything? There is still NO evidence you have done anything.

    I think I am done here. It does not seem like you are paying attention.

  19. #39
    Quote Originally Posted by fumei
    Huh? Of course there is. That is EXACTLY what I posted!
    Yes you did. Now I will be able to print the last page and the page the precedes it regardless of how many pages the document has. I thought it was impossible to code something like that. Wonderful.


    [VBA]With Selection
    .EndKey Unit:=wdStory
    .InsertBreak Type:=wdSectionBreakNextPage
    .InsertFile FileName:="Other.doc", Range:=""


    End With[/VBA]

    For the future reference, in case someone comes here seeking for the same thing, here's Fumei's code. It will automatically insert another file as the last page keeping it's original heading in the process, and then it will automatically print that page and the page before, regardless of the number of pages that the original document has. All of this in one macro, which means one click.

    Big thanks to Fumei, macropod and all the rest who spent time in writing this code.
    Last edited by Zack; 04-29-2012 at 02:06 AM.

  20. #40
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    This post doesn't really help your cause, Zack.

    Unless you think this entire forum is set up to make fun of people who know less about VBA than the experts who post answers, or the forum was set up to tease people by knowing an answer but not giving it, your sarcasm not only doesn't help, but you contribute to the problem by posting bad information.

    The above code does not do what you say it does, obviously. It is also probably not even the best way to accomplish what you would want to do.

    However, it is a sample of the kind of code which would be the result of recording a macro to get you closer.

    What has been said repeatedly in this thread is two things:
    1) the answer is not simple because it revolves around items which can only be tested in your specific environment

    2) requests for you to post a document with samples of your progress, things you've tried, etc.

    For example, if you had tried to record the macro of the process Fumei had described with his 4 steps of basic logic, and then posted that recording (after cleaning it up an trying to understand it), you would be closer to your goal.

    These requests have been made not because people are lazy, but because you don't have the capacity to ask the right very specific conceptual programming questions, and thus seeing an actual document/recorded macro would help give concrete information your lack of knowledge prevents you from conveying.

    But there's really no need to get sarcastic with people who are, ultimately, trying to help you

Posting Permissions

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