Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2014, 12:47 PM
tfurnivall tfurnivall is offline Problems setting HeadingFormat - and making it work Windows XP Problems setting HeadingFormat - and making it work Office 2010 32bit
Novice
Problems setting HeadingFormat - and making it work
 
Join Date: Sep 2012
Posts: 9
tfurnivall is on a distinguished road
Default Problems setting HeadingFormat - and making it work

Disclaimer - also posted to another forum, but this seems to have better tools!



I am creating two documents from a PowerPoint script (GenScript) - a Recording Script and a Shooting Script. Other than the number of columns, the Recording Script and Shooting Script are constructed in identical manner. This description concentrates on the Recording script, which is simpler in design.

This procedure works by going through the Notes pages of a PowerPoint presentation, and creating a document with four columns (Slide#, Text, Time and Comments). The Notes text from each slide goes in the Text column - the Slide number goes in (surprisingly enough) the Slide # column, and the other two are used to capture timings and other comments.

I have a header row, with different formatting, and want this header row to appear at the top of each page. Here is the procedure that I use to Initiate each script:
Code:
Sub InitiateScript(ThisScript As Word.Document, ScriptType As String)

'   NOTE This procedure uses word functions (InchesToPoints), which MUST be qualified with
'   the instance of word that is being referenced. If not, then the code will not repeat.
'   (Comment from Micro$oft: This bahavior is by design) !?
'   http://support.microsoft.com/kb/189618

Dim ColWidths(SNotesCol) As Single

Dim TableHeaderText As String
Dim TableRange As Range
Dim TableCount As Long
Dim OldWidth As Single
Dim NewWidth As Single
Dim ScriptTable As Word.Table

'   External variables exist for RecordScriptTable &
'   ShootingScriptTable - used in many of the procedures

'   Set up the basic skeleton of the script document
CreateScriptCoverPage ThisScript, ScriptType
CreateScriptHeaders ThisScript, ScriptType
CreateScriptTableOfContents ThisScript, ScriptType

'   Set up a range comprising the whole (empty) document
TableHeaderText = ""
Set TableRange = ThisScript.Range
TableRange.Collapse Direction:=wdCollapseEnd
TableRange.InsertAfter Text:=TableHeaderText

'   Create a table with the right number of columns
TableCount = ThisScript.Tables.Count
If ScriptType = "Recording" Then
   Set RecordingScriptTable = ThisScript.Tables.Add(TableRange, ScriptTableInitialRows, RecordingScriptNumColumns)
   Set ScriptTable = RecordingScriptTable
ElseIf ScriptType = "Shooting" Then
   Set ShootingScriptTable = ThisScript.Tables.Add(TableRange, ScriptTableInitialRows, ShootingScriptNumColumns)
   Set ScriptTable = ShootingScriptTable
End If

If ScriptType = "Recording" Then
   With ScriptTable.Range
        .Cells(RSlideCol).Range.InsertBefore Text:="Slide #"
        .Cells(RTextCol).Range.InsertBefore Text:="Script"
        .Cells(RTimeCol).Range.InsertBefore Text:="Time"
        .Cells(RNotesCol).Range.InsertBefore Text:="Comments"
   End With
ElseIf ScriptType = "Shooting" Then
   With ScriptTable.Range
        .Cells(SSlideCol).Range.InsertBefore Text:="Slide #"
        .Cells(SAnimationCol).Range.InsertBefore Text:="Animation #"
        .Cells(STimeCol).Range.InsertBefore Text:="Time"
        .Cells(STitleCol).Range.InsertBefore Text:="Slide Title"
        .Cells(STextCol).Range.InsertBefore Text:="Script"
        .Cells(SFXCol).Range.InsertBefore Text:="FX"
        .Cells(SNotesCol).Range.InsertBefore Text:="Comments"
   End With
End If

'   Set column widths
ScriptTable.PreferredWidthType = wdPreferredWidthAuto

'   Columns for Recording Script
If ScriptType = "Recording" Then
   ScriptTable.Columns(RSlideCol).Width = WordApp.InchesToPoints(0.75)
   ScriptTable.Columns(RSlideCol).Select
   WordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

   ScriptTable.Columns(RTextCol).Width = WordApp.InchesToPoints(6.5)
   
   ScriptTable.Columns(RTimeCol).Width = WordApp.InchesToPoints(1#)
   ScriptTable.Columns(RTimeCol).Select
   WordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

   ScriptTable.Columns(RNotesCol).Width = WordApp.InchesToPoints(2#)
End If

'   Columns for Shooting Script
If ScriptType = "Shooting" Then
   ScriptTable.Columns(SSlideCol).Width = WordApp.InchesToPoints(0.5)
   ScriptTable.Columns(SSlideCol).Select
   WordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

   ScriptTable.Columns(STitleCol).Width = WordApp.InchesToPoints(1)

   ScriptTable.Columns(SAnimationCol).Width = WordApp.InchesToPoints(0.5)
   ScriptTable.Columns(SAnimationCol).Select
   WordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

   ScriptTable.Columns(STimeCol).Width = WordApp.InchesToPoints(0.5)
   ScriptTable.Columns(STimeCol).Select
   WordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

   ScriptTable.Columns(STextCol).Width = WordApp.InchesToPoints(4)
   ScriptTable.Columns(SFXCol).Width = WordApp.InchesToPoints(1.5)
   ScriptTable.Columns(SNotesCol).Width = WordApp.InchesToPoints(1.5)
End If

'   Adjust the first row
With ScriptTable.Rows(1)
    .Shading.Texture = wdTextureNone
    .Shading.ForegroundPatternColor = wdColorAutomatic
    .Shading.BackgroundPatternColor = wdBlack
    .Range.Font.Name = "Albertus MT"
    .Range.Font.Size = 10
End With

ScriptTable.Rows(1).HeadingFormat = True

With ScriptTable.Borders
    .OutsideLineStyle = wdLineStyleSingle
    .OutsideColor = wdColorBlack
    .OutsideLineWidth = wdLineWidth100pt
    .InsideLineStyle = wdLineStyleSingle
    .InsideColor = wdColorBlack
    .InsideLineWidth = wdLineWidth100pt
End With

End Sub
I've also attached a Recording Script that was created by this procedure. As you can see the "Repeat as Header Row at top of each Page" is checked. However, it doesn't actually do what it's supposed to

I had a response on the other forum from a couple of people - thanks. But I couldn't figure out how to attach code or files. Hence this second, duplicative posting.

Any ideas?

Thanks,

Tony
Attached Files
File Type: docx RT010101 -- Recording Script.docx (23.9 KB, 8 views)
Reply With Quote
  #2  
Old 04-07-2014, 09:30 PM
macropod's Avatar
macropod macropod is offline Problems setting HeadingFormat - and making it work Windows 7 32bit Problems setting HeadingFormat - and making it work Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Since you have cross-posted, please provide links to the other forum from here and, at the other forum, links to here.

For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

PS: There is nothing in that code to indicate a problem with the table creating or heading rows. However, there is also no indication of whether the table thus created spans a page boundary.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-08-2014, 06:02 AM
tfurnivall tfurnivall is offline Problems setting HeadingFormat - and making it work Windows XP Problems setting HeadingFormat - and making it work Office 2010 32bit
Novice
Problems setting HeadingFormat - and making it work
 
Join Date: Sep 2012
Posts: 9
tfurnivall is on a distinguished road
Default

Here beginneth the apology for a social lapse.


I also cross-posted this request at http://social.technet.microsoft.com/...vba?forum=word, but I was not able to upload code there.



Many thanks to Paul Edstein who provided assistance on the etiquette of cross-posting. I will not continue to work the other appearance of the thread, but will continue to try and resolve the issue here.


Current question is whether or not I have actually managed to create two (or more, even)tables that are butted right up next to each other (making the meaning of repeating the row somewhat irrelevant). I'll try this out in just a bit.


Apologies for my lapse in good taste, and thanks to those who responded there.


Tony
Reply With Quote
  #4  
Old 04-08-2014, 06:12 AM
tfurnivall tfurnivall is offline Problems setting HeadingFormat - and making it work Windows XP Problems setting HeadingFormat - and making it work Office 2010 32bit
Novice
Problems setting HeadingFormat - and making it work
 
Join Date: Sep 2012
Posts: 9
tfurnivall is on a distinguished road
Default SOme results!

Well, I wrote a little script:
Code:
Sub TestNumTables()

Dim t As Long

t = ActiveDocument.Tables.Count

If t = 1 Then
   Debug.Print "This document has just "; t; "table (Phew!)"
Else
   Debug.Print "This table seems to have"; t; " tables. Now to see if I can consolidate them..."
End If

End Sub
And, when I run it:
Code:
This document has just  1 table (Phew!)
So... it looks like I have only one table - no breaks or real good friends snuggling up together, but still I can't get the top row repeating. I have actually done this before, but (it was many years ago) no longer have the code :-(

Any ideas? (Can't attach a .docm file , so the entire script is given above; the other two uploads are available elsewhere on this thread)

Thanks,

Tony
Reply With Quote
  #5  
Old 04-08-2014, 03:09 PM
macropod's Avatar
macropod macropod is offline Problems setting HeadingFormat - and making it work Windows 7 32bit Problems setting HeadingFormat - and making it work Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Tony,

Without actually seeing the problem Word document and the corresponding PowerPoint presentation (with code), it can be difficult to diagnose the issue. Can you attach the files as a zip archive to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 04-08-2014, 04:04 PM
tfurnivall tfurnivall is offline Problems setting HeadingFormat - and making it work Windows XP Problems setting HeadingFormat - and making it work Office 2010 32bit
Novice
Problems setting HeadingFormat - and making it work
 
Join Date: Sep 2012
Posts: 9
tfurnivall is on a distinguished road
Default Requested files (3) to emulate the GenScript process

Hi Paul

I've attached three files - the resulting script document (RT010101.docx), the GenScript PowerPoint file, and the presentation used as the source for the script file (RT010101.pptx).

GenScript.pptm has an extended suffix, indicating that you shold simply trim it back to .pptm.

If you want to emulate my process entirely, drop the RT010101.pptx and the GenScript.pptm into a convenient location, preferable one level down from something like MyDocuments (ie My Documents/Test/Genscript.pptx, and My Documents/Test/RT010101.pptx)

There is a form in the GenScript VBA fork. It's still in development, so you'll need to run it by opening up the form and keying F5.

You'll be asked for to browse for a presentation - use the dialog to navigate to My Documents/Test, and pick up the RT010101.pptx file. You'll then be asked to select a directory for the script file. Browse back to the My Documents/Test directory and Select it - it's not very good at suggesting a default directory yet.

Them make certain to select Create Recording script, and click GenScript.
Attached Files
File Type: pptx GenScript.pptm.cut back to.pptx (166.5 KB, 9 views)
File Type: docx RT010101 -- Recording Script.docx (23.9 KB, 12 views)
File Type: pptx RT010101.pptx (124.5 KB, 9 views)
Reply With Quote
  #7  
Old 04-08-2014, 05:12 PM
macropod's Avatar
macropod macropod is offline Problems setting HeadingFormat - and making it work Windows 7 32bit Problems setting HeadingFormat - and making it work Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I tried to run your code, but it fell over as soon as I clicked the browse button, at:
Me.lblPresentationDirectory = "*PROJECT*" & Mid(Me.lblPresentationDirectory.Caption, l + 1)
with a compile error "can't find project or library".

Leaving that aside, I also had a look at your document. To be sure, the 'heading row repeat' option is checked, but the row doesn't repeat. But! Unchecking, then re-checking the option fixes the problem.

I also note that your code has a number of places where it's trying to manipulate the heading format:
Sub ProcessScriptBlock -
ScriptTable.Rows(RowCount).HeadingFormat = False

Function CreateScriptForPresentation -
If GenScript.CreateRecordingScript Then
RecordingScriptTable.Rows(1).HeadingFormat = True
RecordingScript.Close SaveChanges:=wdSaveChanges
End If
If GenScript.CreateShootingScript Then
ShootingScriptTable.Rows(1).HeadingFormat = True
ShootingScript.Close SaveChanges:=wdSaveChanges
End If

Sub InitiateScript -
ScriptTable.Rows(1).HeadingFormat = True

Might I suggest you leave all HeadingFormat manipulations till the very end, then use a simple loop like the following before saving:
Code:
Dim Tbl As Word.Table
For Each Tbl In WordApp.ActiveDocument.Tables
  With Tbl
    .Rows.HeadingFormat = False
    .Rows(1).HeadingFormat = True
  End With
Next
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 04-08-2014, 07:21 PM
tfurnivall tfurnivall is offline Problems setting HeadingFormat - and making it work Windows XP Problems setting HeadingFormat - and making it work Office 2010 32bit
Novice
Problems setting HeadingFormat - and making it work
 
Join Date: Sep 2012
Posts: 9
tfurnivall is on a distinguished road
Default

Thanks for the feedback, Paul. I'm quoting from the help on Mid (since that seems to be where the app hiccupped for you:
Code:
Mid Function

                                                                                                                                                              This page is specific to the Visual Basic for  Applications (VBA) Language Reference for Office 2010.    Returns a Variant (String) containing a specified number of  characters from a string.
 Syntax
 Mid(string, start[,  length])
 The Mid function syntax has these named  arguments:
       Part
  Description
   string
  Required. String  expression from which characters are returned. If string  contains Null,  Null is returned.
   start
  Required; Long.  Character position in string at which the part to be taken begins.  If start is greater than the number of characters in  string, Mid returns a zero-length string  ("").
   length
  Optional; Variant (Long). Number of characters to return. If  omitted or if there are fewer than length characters in the text  (including the character at start), all characters from the  start position to the end of the string are  returned.

 Remarks
 To determine the number of characters in string, use the  Len function.
I'm using Office 2010 - how about you?

I also tried un-setting and re-setting the flag, and it still doesn't function properly. Perhaps this is a corner case on my particular environment:

XP SP3
Firefox 27.0.1
Office 2010 14.0.6129.5000

It's a trivial nit, and I can certainly use the scripts that are created, but it sure would be nice to find out exactly what is, or is not, going on!

Tony
Reply With Quote
  #9  
Old 04-08-2014, 07:27 PM
macropod's Avatar
macropod macropod is offline Problems setting HeadingFormat - and making it work Windows 7 32bit Problems setting HeadingFormat - and making it work Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

hi Tony,

I know what the MID function is - I've used it quite a lot in my own coding. It's just that your code threw a wobbly on my system (32-bit Office 2010 on 64-bit Win 7) for whatever reason and I didn't have time to sort it out. I might try a re-boot later on and see if it goes away.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 04-09-2014, 05:37 AM
tfurnivall tfurnivall is offline Problems setting HeadingFormat - and making it work Windows XP Problems setting HeadingFormat - and making it work Office 2010 32bit
Novice
Problems setting HeadingFormat - and making it work
 
Join Date: Sep 2012
Posts: 9
tfurnivall is on a distinguished road
Default

I couldn't bring myself to imagine that you didn't know it''
However, I think the alternate usage (effectively a Right() without having to calculate the length is possibly less frequently used.

I can create a table programmatically with the desired results, it's just when it has all the other stuff involved with splitting out text and massaging it, that Word seems to go flaky.

Tony
PS Note usage of "seems"; I'm a firm believer that if a piece of system software "seems" not to be working, the first thing to examine is the conceptual understanding of the programmer who produced the anomaly
Reply With Quote
  #11  
Old 04-16-2014, 10:09 PM
macropod's Avatar
macropod macropod is offline Problems setting HeadingFormat - and making it work Windows 7 32bit Problems setting HeadingFormat - and making it work Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Tony,

I've both tracked down the 'Mid' problem and solved the heading rows issue!

The 'Mid' problem results from your code having a reference set to something called 'ScriptPW 1.0 Type Library', which I don't have on my system. I deleted that and the code seems to run fine without it. You might consider whether you need that reference - and each of the other non-standard references you have set.

As for the table heading row, solving that is as simple as deleting:
ScriptTable.Rows(1).HeadingFormat = True
from the 'InitiateScript' sub. You also don't need:
ScriptTable.Rows(RowCount).HeadingFormat = False
in the 'ProcessScriptBlock' sub.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 04-17-2014, 06:43 AM
tfurnivall tfurnivall is offline Problems setting HeadingFormat - and making it work Windows XP Problems setting HeadingFormat - and making it work Office 2010 32bit
Novice
Problems setting HeadingFormat - and making it work
 
Join Date: Sep 2012
Posts: 9
tfurnivall is on a distinguished road
Default Thanks for the solution!

Thanks, Paul

Not only for solving the problem, but for investing the time to track down some of the arcana of the code that was creating it. I guess it's an example of 2 belts and suspenders being a little too much!

Suggested corrections made, and voila, it works as I hoped.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems setting up email accounts. macc2014 Outlook 0 02-18-2014 12:36 PM
Problems setting HeadingFormat - and making it work work of labor vs work of excavator ketanco Project 1 02-11-2014 08:53 AM
Problems setting HeadingFormat - and making it work work vs regular work. and how regular work works user0044 Project 5 03-06-2012 07:28 AM
Problems setting HeadingFormat - and making it work Making the IF field work (not Mail Merge) Caroline Mail Merge 5 04-11-2011 04:17 PM
Problems setting HeadingFormat - and making it work Work Offline Setting thomas34461 Outlook 1 04-04-2011 01:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft