Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2014, 07:45 PM
donaldadams1951 donaldadams1951 is offline Section - Page Break changes to Section - continuous? Windows XP Section - Page Break changes to Section - continuous? Office 2010 32bit
Advanced Beginner
Section - Page Break changes to Section - continuous?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default Section - Page Break changes to Section - continuous?

Word 2010

I hope I can describe this well enough for you to follow.

The Word application I am enhancing is used to create reports. The user can tell Word to "protect" the existing document which it appears it does by by adding a Section Break(Next Page) to the end of the document, then protecting the document, preserving all the existing content and puts the cursor on Page 2 for instance. Then anything that is added goes on Page 2. If the cursor is put in page 1 it jumps to Page 2. This is all being done automatically, the user does not manually insert the Section Break(Next Page). After the section is protected the section now says "end of Protected Section". This is being done by the add-in I did not write.

If I add another section(CreateSection) to page 2 of the "protected document" it works fine. I can put whatever I want in the newly added section. If I now choose to unprotect(UnProtectFORM)) the document and delete the section(GetAndRemoveSectionByInstanceNumber) I added with the code listed below and protect document(ProtectFORM), the Section Break(Next Page) that was on Page 1 seems to convert to Section Break(Continuous) so now my cursor can be on Page 1 which is undesirable.

I have put in parentheses all the code names I used. They are listed below.

------------------
Code:
 
 Sub CreateSection()
   ' Called by InsertSelectedSynopticReportAtCursor
   Dim strImageTag
   System.Cursor = wdCursorWait
  
  ' Step #0, test
 ' Selection.InsertBreak Type:=wdSectionBreakContinuous
  
  
  strImageTag = "<ImageTable: efrm" & ReportInstance & ">[EmbeddedReport]efrm goes here[/EmbeddedReport]"
   ' Step #1
  Selection.InsertBreak Type:=wdSectionBreakContinuous
  
  ' Step #2
  Selection.Font.Hidden = True
  Selection.TypeText (strImageTag)
  Selection.Font.Hidden = False
  
  ' Step #3
  Selection.InsertBreak Type:=wdSectionBreakContinuous
    
End Sub
Code:
 
 Sub UnProtecteFRM()
   Application.ScreenUpdating = False
  ActiveWindow.View.ShowHiddenText = True
   System.Cursor = wdCursorWait
    
  Set aDoc = ActiveDocument
   If aDoc.ProtectionType <> wdNoProtection Then
   ' MsgBox ("UnProtecteFRM -Get Password")
    aDoc.Unprotect Password:="PwrMcW3pzf6"
  End If
   With Selection.Find
    
    .ClearFormatting
    .Text = "ImageTable: efrm"
    .Replacement.ClearFormatting
    .Replacement.Text = "ImageTable efrm"
    .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
    
  End With
    
  ActiveWindow.View.ShowHiddenText = False
  Application.ScreenUpdating = True
    
End Sub
Code:
 
 Sub GetAndRemoveSectionByInstanceNumber()
   ' done with Macropod's help on vba express forum
  ' http://www.vbaexpress.com/forum/show...ins-my-keyword
  
  ' 12/01/2013, dla
  ' 12/03/2013, dla
   ' there is an assumption that the document is unprotected.
  ' we need to see if this works if the document is protected.
   Dim strSearchString As String
  
  intSectionCount = -1
  
  
  ' these 2 lines are not necessary(?)
  Application.ScreenUpdating = False
  ActiveWindow.View.ShowHiddenText = True
  
  strSearchString = "Inst#: " & ReportInstance
  
  System.Cursor = wdCursorWait
   ' start at top of document
  Selection.HomeKey Unit:=wdStory
  
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  With ActiveDocument.Range
  
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = strSearchString
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = True
      .Execute
    End With
    
    If .Find.Found = True Then
      .End = .Duplicate.Sections(1).Range.End
      .Start = .Duplicate.Sections(1).Range.Start - 1
      .Duplicate.Text = vbNullString
    End If
    
  End With
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  
  ActiveWindow.View.ShowHiddenText = False
  Application.ScreenUpdating = True
  
  Application.ScreenRefresh
 End Sub
Code:
 
 Sub UnProtectFORM()
   Application.ScreenUpdating = False
  ActiveWindow.View.ShowHiddenText = True
   System.Cursor = wdCursorWait
    
  Set aDoc = ActiveDocument
   If aDoc.ProtectionType <> wdNoProtection Then

    aDoc.Unprotect Password:="PwrMcW3pzf6"
  End If
   With Selection.Find
    
    .ClearFormatting
    .Text = "ImageTable: efrm"
    .Replacement.ClearFormatting
    .Replacement.Text = "ImageTable efrm"
    .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
    
  End With
    
  ActiveWindow.View.ShowHiddenText = False
  Application.ScreenUpdating = True
    
End Sub
Code:
 
 Sub ProtectFORM()
 
  Application.ScreenUpdating = False
  ActiveWindow.View.ShowHiddenText = True
  
  
  Selection.HomeKey Unit:=wdStory
    
  With Selection.Find
    
    .ClearFormatting
    .Text = "ImageTable efrm"
    .Replacement.ClearFormatting
    .Replacement.Text = "ImageTable: efrm"
    .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
        
  End With
  
  'If OriginalProtection <> wdNoProtection Then
   ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="PwrMcW3pzf6"
  '  MsgBox ("ProtecteFRM")
 ' End If
  
  ActiveWindow.View.ShowHiddenText = False
  Application.ScreenUpdating = True
 End Sub

Reply With Quote
  #2  
Old 03-21-2014, 03:13 AM
macropod's Avatar
macropod macropod is online now Section - Page Break changes to Section - continuous? Windows 7 32bit Section - Page Break changes to Section - continuous? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

The only references I can see in your code to the creation of Section breaks is for Continuous breaks. In any event, if you want to change an existing break type, you can use code like:
ActiveDocument.Sections(2).PageSetup.SectionStart = wdSectionNewPage
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-21-2014, 07:33 AM
donaldadams1951 donaldadams1951 is offline Section - Page Break changes to Section - continuous? Windows XP Section - Page Break changes to Section - continuous? Office 2010 32bit
Advanced Beginner
Section - Page Break changes to Section - continuous?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default Section Break(Next Page)

The Section Break(Next Page) is created by the other Word add-in that I do not control.

Can I "unprotect" one section at a time?
Reply With Quote
  #4  
Old 03-21-2014, 03:34 PM
macropod's Avatar
macropod macropod is online now Section - Page Break changes to Section - continuous? Windows 7 32bit Section - Page Break changes to Section - continuous? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by donaldadams1951 View Post
Can I "unprotect" one section at a time?
Yes, but that is not the issue. Since you're deleting section(s) by code, the code you're using for that can change whatever Section break you're concerned with to another type; that's what the snippet I posted does.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-23-2014, 04:41 PM
donaldadams1951 donaldadams1951 is offline Section - Page Break changes to Section - continuous? Windows XP Section - Page Break changes to Section - continuous? Office 2010 32bit
Advanced Beginner
Section - Page Break changes to Section - continuous?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default Can the snippet be changed to leave Section Break(Next Page) alone?

I need to leave any Section Break(Next Page) alone. Is there a way to modify the code snippet so if the Section Break is a Next Page it leaves it alone? I do not want Section Break(Next Page) converting to Section Break(Continuous).
Reply With Quote
  #6  
Old 03-23-2014, 07:41 PM
macropod's Avatar
macropod macropod is online now Section - Page Break changes to Section - continuous? Windows 7 32bit Section - Page Break changes to Section - continuous? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

The simplest approach would be to store the Section break type before deleting, then re-apply it afterwards. That way you don't need to concern yourself with what type it was or might have changed to. For example, supposing you wanted to delete Section 2:
Code:
Sub Demo()
Dim ScnBrk As Long, i As Long
i = 2
With ActiveDocument
  ScnBrk = .Sections(i - 1).PageSetup.SectionStart
  .Sections(i).Range.Delete
  .Sections(i).PageSetup.SectionStart = ScnBrk
End With
End Sub
With this code, it really doesn't matter whether the Section break was continuous, next page, first page or even page - it'll be restored to its prior state.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 03-24-2014, 01:14 PM
donaldadams1951 donaldadams1951 is offline Section - Page Break changes to Section - continuous? Windows XP Section - Page Break changes to Section - continuous? Office 2010 32bit
Advanced Beginner
Section - Page Break changes to Section - continuous?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default Where in the code am I deleteing the Section Break(Next Page)?

When I insert my report into the document, I am inserting a Section Break(Continuous) then inserting my report then inserting another Section Break(Continuous). Then I protect the report I inserted by protecting the section it is in.

That works fine. Now if I remove the section that contains the report it removes the new section I inserted but also converts the Section Break(Next Page) to a Section Break(Continuous).

I do not see in the snippet why it is doing that. Where in the snippet that deletes the section that has my report do I put the new code that stores the Section Break type in the previous section and puts it back when finished. I'm sorry but I guess I am too inexperienced to see where I should do that in the "GetAndRemoveSectionByInstanceNumber" sub-routine.
Reply With Quote
  #8  
Old 03-24-2014, 03:42 PM
macropod's Avatar
macropod macropod is online now Section - Page Break changes to Section - continuous? Windows 7 32bit Section - Page Break changes to Section - continuous? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Replace your 'GetAndRemoveSectionByInstanceNumber' sub with:
Code:
Sub GetAndRemoveSectionByInstanceNumber()
Dim strSearchString As String, ScnBrk As Long, i As Long
strSearchString = "Inst#: " & ReportInstance
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = strSearchString
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  If .Find.Found = True Then
    i = .Duplicate.Sections(1).Index - 1
    ScnBrk = .Sections(i).PageSetup.SectionStart
    .Duplicate.Sections(1).Range.Delete
    .Sections(i).PageSetup.SectionStart = ScnBrk
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 03-24-2014, 06:12 PM
donaldadams1951 donaldadams1951 is offline Section - Page Break changes to Section - continuous? Windows XP Section - Page Break changes to Section - continuous? Office 2010 32bit
Advanced Beginner
Section - Page Break changes to Section - continuous?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default Error with new snippet...

I get the following error on this line...

ScnBrk = .Sections(i).PageSetup.SectionStart


Run-time error '5941'
The requested member of the collection does not exist



Code:
 
 Sub GetAndRemoveSectionByInstanceNumber()
  Dim strSearchString As String
  Dim ScnBrk As Long
  Dim i As Long
  
  ' start at top of document
  Selection.HomeKey Unit:=wdStory
  
  System.Cursor = wdCursorWait
   strSearchString = "Inst#: " & ReportInstance
  
  With ActiveDocument.Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = strSearchString
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = True
      .Execute
    End With
    If .Find.Found = True Then ' .Find.Found = True Then
      i = .Duplicate.Sections(1).index - 1
      ScnBrk = .Sections(i).PageSetup.SectionStart 'error here
      .Duplicate.Sections(1).Range.Delete
      .Sections(i).PageSetup.SectionStart = ScnBrk
    End If
  End With
End Sub
Reply With Quote
  #10  
Old 03-24-2014, 06:32 PM
macropod's Avatar
macropod macropod is online now Section - Page Break changes to Section - continuous? Windows 7 32bit Section - Page Break changes to Section - continuous? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

When it gives the error, what is the value of i? Also, is there any particular reason for not using the code as posted? The rest of what you have in that sub is unnecessary clutter.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 03-24-2014, 07:41 PM
donaldadams1951 donaldadams1951 is offline Section - Page Break changes to Section - continuous? Windows XP Section - Page Break changes to Section - continuous? Office 2010 32bit
Advanced Beginner
Section - Page Break changes to Section - continuous?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default OK. commented out the code and have the value...

i = 3

Code:
 
 Sub GetAndRemoveSectionByInstanceNumber()
  Dim strSearchString As String
  Dim ScnBrk As Long
  Dim i As Long
  
  ' start at top of document
'  Selection.HomeKey Unit:=wdStory
  
'  System.Cursor = wdCursorWait
   strSearchString = "Inst#: " & ReportInstance
  
  With ActiveDocument.Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = strSearchString
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = True
      .Execute
    End With
    If .Find.Found = True Then ' .Find.Found = True Then
      i = .Duplicate.Sections(1).index - 1
      MsgBox (CStr(i))
      ScnBrk = .Sections(i).PageSetup.SectionStart 'error here
      .Duplicate.Sections(1).Range.Delete
      .Sections(i).PageSetup.SectionStart = ScnBrk
    End If
  End With
End Sub
Reply With Quote
  #12  
Old 03-24-2014, 08:06 PM
macropod's Avatar
macropod macropod is online now Section - Page Break changes to Section - continuous? Windows 7 32bit Section - Page Break changes to Section - continuous? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 am unable to replicate that error. Can you attach a document to a post with some representative data, including an indication of what you want to delete (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab. If it's a docm file, you'll need to zip it first.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 03-24-2014, 10:19 PM
donaldadams1951 donaldadams1951 is offline Section - Page Break changes to Section - continuous? Windows XP Section - Page Break changes to Section - continuous? Office 2010 32bit
Advanced Beginner
Section - Page Break changes to Section - continuous?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default There is also an add-in...and a .dotm file

If I send you a document that was created that had a Word add-in will the document contain all you need to view it correctly? I assume you will also want the .dotm file I use and have loaded in the user Word start-up folder.

If you tell me an email address I can send them to you. I can't put it the document nor the .dotm file in public forum.
Reply With Quote
  #14  
Old 03-27-2014, 07:03 PM
macropod's Avatar
macropod macropod is online now Section - Page Break changes to Section - continuous? Windows 7 32bit Section - Page Break changes to Section - continuous? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Try it this way:
Code:
Sub GetAndRemoveSectionByInstanceNumber()
Dim ScnBrk As Long
With ActiveDocument.Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "Inst#: " & ReportInstance
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = True
      .Execute
    End With
    If .Find.Found = True Then
      With .Duplicate
        ScnBrk = .Sections(1).PageSetup.SectionStart
        .Sections(1).Range.Delete
        .Sections(1).PageSetup.SectionStart = ScnBrk
      End With
    End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Section - Page Break changes to Section - continuous? Deleting section break and retaining section properties New Daddy Word 6 02-03-2014 07:09 PM
Section - Page Break changes to Section - continuous? Section Break (Next Page) replaces Section Break (Continuous) when deleted Carlabasson Word 2 03-25-2013 10:13 PM
Continuous section break and column changes Jim B Word 3 11-27-2012 02:25 PM
why the "section break-next page" is switched to "section break-continuous"? Jamal NUMAN Word 6 12-14-2011 03:35 PM
Section - Page Break changes to Section - continuous? Section Break Continuous: doesn't affect the format of the page numbering Jamal NUMAN Word 2 06-22-2011 04:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:58 AM.


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