How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Michael Hannigan Your Own Question
Michael Hannigan
Michael Hannigan, Office Specialist
Category: Microsoft Office
Satisfied Customers: 11819
Experience:  25+ Years Experience in Computers and Electronics. Microsoft Certified MCSE, MCDBA, MCP, Microsoft Partner
Type Your Microsoft Office Question Here...
Michael Hannigan is online now
A new question is answered every 9 seconds

I have a 740 page .doc in Word 2003 that I am trying to

Customer Question

Hi. I have a 740 page .doc in Word 2003 that I am trying to publish both as a 5.5 x 8.5 pBook and as various eBook PDF with several smaller "page" sizes.
I need a VB macro for word that will look for tables, and expand/contract the last column of each table such that the total width of the table is a constant that is in the VB macro, thus the table will take exactly the entire page width.
I'm sure there is something out there like that.
Thank you
Submitted: 2 years ago.
Category: Microsoft Office
Expert:  Christopher Love replied 2 years ago.
Hello, my name is Chris. I have read your request and I agree this should be possible. I'll need some time to write the macro and test it before I send it to you. Can you send me a sample page(s) so I can see exactly what the macro should perform? If you send it on and upload your page(s) there, I'll get you an answer with either the Macro or whether I can do it by tomorrow. Let me know if you want me to proceed.
Expert:  Michael Hannigan replied 2 years ago.
Hello. My name is Michael.
I'm not really crazy about the solution but this is what I found
Thing I don't like about it is that it relies on using Excel as well which makes it pretty fragile. But, it could be implemented to customize the tables programmatically.
Sub test()
folder_Modules_xls = "C:\Modules"
path_template_report = "C:\template_report.docx"
'Get all the selected modules and deduct Bookmarks by removing extension (*.xls or *.xlsx)
SelectedModules = "test.xlsx"
'OPEN main Word File
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(path_template_report)
objWord.Visible = True
'Extract Bookmark that will be used in word file.
Bookmarks = Left(SelectedModules, WorksheetFunction.Search(".", SelectedModules) - 1)
'OPEN Excel file to print into the main Word file
Set wb = Workbooks.Open(folder_Modules_xls & "\" & SelectedModules)
'READ the number of range name in the xls file corresponding to the number of print area
printAreaQty = ActiveWorkbook.Names.Count
'rRange = RecoverNameRange("Print_Area1")
'In the Word file, go to the corresponding bookmark
'Skip a line
objWord.Selection.TypeText (vbCrLf) 'return carriage
'Select the print area #1 in the xls file
'Paste the table at the selected bookmark in the main word doc.
Application.CutCopyMode = False
With objDoc.Tables(objDoc.Tables.Count)
.AutoFitBehavior wdAutoFitWindow 'fit to the page
.Rows.SetHeight RowHeight:=objWord.CentimetersToPoints(0.5), HeightRule:=wdRowHeightExactly 'adjust row height
End With
'Close Excel file
Workbooks(SelectedModules).Close SaveChanges:=False
Set wb = Nothing
Set objWord = Nothing
Set objDoc = Nothing
End Sub