Formatting issues duplicating table - vba

Forward
I am making a "label program" that will print waybill information. Consists of a table in Word on a custom 3x5 inch document with 0 margins.
I currently have a simple form that, if you need copies, it will edit one of the cells so that each time it prints the "pieces count" is incremented. 1of10, 2of10, 3of10.....
While that worked the code submitted a separate print job for each "label". That created a problem for the end user where they would have to wait about 5-10 seconds between print jobs. When printing a couple of hundred of these at a time those seconds can add up.
Corrective solution
To try an alleviate this problem I wanted to make copies of the table so that 100 labels would be printed as one 100 page document. Found several solutions for copying pages of text but I have tables which complicated things. The closest solution I have found was:
With ActiveDocument
.Tables(1).Range.Copy
.Range.Select
'.Range.InsertAfter (Chr(11))
Selection.Collapse wdCollapseEnd
Selection.Paste
End With
And this does make a perfect copy of the table however it is merging the tables together. So if I wanted to loop this to create several more labels it would be doubling up the results every time since the code above just copies the first tabel.
To try and fix that issue I added a line break (vertical tab) before the paste. You will see that as the commented out line in the above snippet. This breaks up the tables but adds too much whitespace in between.
Page breaks seems like the solution here. While those did make the table break up they ended up creating a blank page in between each label which I was having enough of a time clearing from the GUI let alone in VBA.
The actual question
How can I take a table that is perfectly designed to fit on one 3x5 inch page and duplicate it X times. The caveat is I need to be able to find the cell programically that contains the pieces text. Currently I can use these absolute reference for the first table
ActiveDocument.Tables(1).Cell(5, 1).Range.Text
So if I had 3 tables for instance I need to be able to call each table and edit the text of the Cell(5, 1).
In case you ask
I know this functionality is better placed inside actual label programs like Bartender but those cost money that the company will not allocate for the only label my company uses.

The right concept was there. We needed to add a break in between the tables to disassociate them. Adding the vertical tab Chr(11) was obviously not the correct way to do it.
A proper section break would be the route to go here. Looking at MSDN you can see there are multiple types of section breaks. After testing a desirable outcome was acheived from using wdSectionBreakNextPage which is a "Section break on next page."
Basically just needed to add one line to the above code.
With ActiveDocument
.Tables(1).Range.Copy
.Range.Select
End With
With Selection
.Collapse wdCollapseEnd
.InsertBreak (wdSectionBreakNextPage)
.Paste
End With
I hate the use of Selection and I am going to look into that but for now this does function properly.
Since the tables are not single units we are able to query .Tables in order to edit each page individually.

Related

MS-Word - Pulling down cell content to the next page if a table is broken by a page-break

I have a table in Word that has column titles. When the page breaks the table rolls over to the next page and the headers repeat. However, I also have section titles that are important to see as well. If you look at the example below, I have the section '2' at the top next to sub-section 'C'.
a) I will be generating MHTML dynamically for import into Word so if it is possible to generate MHTML that will enable the above then that would be great. Otherwise ...
b) Is there any way within Word to manually or using VBA mark up the sections so they know to roll over to the next page automatically, so that the table will update itself if there are any changes to page-break locations. Alternatively...
c) I might have to write some VBA that checks that the section numbers are in the right place every time the VBA code is manually run, although I suspect that might start to get messy as I will also have to remove any existing 'pulled' section numbers that might have been inserted.
Thanks

Can I use the Shrink Method for the whole document in word

I don't know anything about code. I work with e-learnings in Storyline 3. I sometimes localize these e-learnings and use the translation tool in Articulate which basically exports an MS Word file. Sometimes the target languages are longer and I need to decrease the font size by percentage for the whole document. Usually, there are at least 3 different font sizes that I need to decrease accordingly. I am wan to develop a macro that I will use for multiple documents.
I couldn't find a way to do this by percentage, but looks like the Shrink or Grow Methods will do the work! I found this code in the reference page but looks like it works only for a selected object. The issue is that the exported MS Word file is in a table with each text box in the storyline separated to a cell. When I select the whole table it does not work.
If Selection.Type = wdSelectionNormal Then
Selection.Font.Grow
Else
MsgBox "You need to select some text."
End If
Could you please help me and let me know if this would be possible for the whole document, or the selected table? It would be very much appreciated. Thanks in advance.
It is unclear from your question whether the table in the Word document contains the actual text boxes or just the text they contain.
If it is just the text then Shrink may work. I tested this on a document with a single table containing only text:
ActiveDocument.Range.Font.Shrink

In MS-Word how do you VBA split a table inserting a Section Break AND a paragraph mark

wdSectionBreakNextPage does not come with a trailing paragraph mark
I have a massive table i copy from excel to word sprinkled throughout with homemade fields PAGEX and SECTIONX. My macro will change these to page and section breaks, splitting the table for each (what I want). But page breaks come with a trailing paragraph mark before the table and section breaks do not. My feeble attempts to insert a paragraph mark after a section break always ends up with the paragraph mark inside the table.
My goal is to get the same gap between my header and the beginning of the table after both section breaks and page breaks. I think I simply want a macro to insert a paragraph mark after my section breaks similar to the way wdPageBreak works (i.e., between the break and the table). But I'm open to suggestions.
As perhaps further clarification, doing this manually involves creating a new row after a section break, then converting that row to text (quite impractical for the counts I'm looking at).
Do While .Execute
Selection.Delete
Selection.InsertBreak Type:=wdSectionBreakNextPage
Loop
Try:
ActiveDocument.Compatibility(wdSplitPgBreakAndParaMark) = False
thanks free and macro. i probably should have noted that i'm a vba novice (cut-and-paste mostly).
i decided it was easiest to just insert a page break after each section break, and then do a replace of ^m^p by ^p.
this works in my case, but won't work for others reading this if they have existing page breaks they don't want to lose.
GJ

Different PPT templates reacting different on the same macros

I'm new here, so I might have not seen a possibility to upload my problem files, which would make it easier to describe the problem.
Edit: The files a here: https://drive.google.com/file/d/0B--IbmtX58h8TnVrdlRyUXZ5a2dEOVJBQkplVjFuVEVMVXhJ/view?usp=docslist_api
and: https://drive.google.com/file/d/0B--IbmtX58h8TFR6d3FkWlZpSGFVUGF5bHVhRTR5ZTlnbXAw/view?usp=docslist_api
(Thank you for the idea, Steve)
What it is about:
I have two documents with different master templates reacting completely different on the same set of macros and I have no idea how and why this can happen and how to repair or avoid it.
Two of the macros just create objects - one is a single textbox, the other one a group of a rectangle and a textbox . The first mentioned appears on the position defined in the code in one of the templates, but a bit below it in the other one. Even more strange is the behavior of the group. The rectangle appears on the correct position in both of the templates, the textbox only in one of it.
Next is a macro for increasing the paragraphing between text lines by 3 pt. It works fine in one template, but in the other template it increases the spacing by 43.2 pt!
Macro number four is made to set back the paragraphing space after back to 0. This one works fine in both templates.
Funny enough, the mistakes appear in opposite to each other. The single textbox and the group produce their error in the template, where the spacing tool works fine, and the spacing tool does strange things in the template where the single textbox and the group work well.
Any idea will be appreciated!
Thanks,
RG
I work with PowerPoint 2010.
Your footnote is getting misplaced because the default text settings in one presentation are different from those in the other; in this case the auto fit setting.
' in this section of your FOOTNOTE routine:
With .TextFrame
' Add this next line and it will work as expected
.AutoSize = ppAutoSizeNone
.TextRange.Text = "Note: " & vbCrLf & "Source: "
.VerticalAnchor = msoAnchorBottom
Likewise, in your SectionMarker subroutine:
With .TextFrame
' add this
.AutoSize = ppAutoSizeNone
' then the rest of your code
Then it all works as you'd expect. Or at least, it works the same with both templates.

Hiding Page Breaks in Excel

Following on from my previous questions:
I have implemented a series of checkboxes with which users can hide/unhide ranges of data. This is great - it works. The problem is when the users go to print - the hidden data is hidden but the pages are still there but blank.
If the page breaks are left to their own devices then everything is fine - there are no blank sections. When manual page breaks are used then you can see where the data was.
I've tried everything to get rid of the blank areas.
Copying the ranges and recalculating the page breaks is a no-go as the page breaks take upwards of 2 minutes for a fairly small report.
So, how can I print only the ranges that aren't hidden?
Thanks, G.
Haven't tested it, but you could change the print range to only the visible cells:
Public Sub SetPrintRangeToVisible(ByRef ws As Excel.Worksheet)
ws.PageSetup.PrintArea = ws.UsedRange.SpecialCells(xlCellTypeVisible).Address
End Sub
Excel, by default prints only visible cells. You wouldnt have to set the Print area to visible cells as previously suggested.
I suppose you have un-checked the Print Object option in all of the Check-boxes. And that area appears blank, when you print the sheet. If that is the case, read on:
I suggest writing a simple macro that hides the rows that contain the check boxes. Set the visible property of the check boxes to false. Print the sheet, and then return everything back to the original state.
Alternatively, you could just select the rows above the check boxes, then the entire area below the check boxes, and then set that as the PrintArea. That should solve the problem you are having.
Also, I may have wildly misunderstood the situation, in which case, I am sorry I wasted your time.