Michael 514
12-10-2005, 11:30 PM
Hi all!!
Long time no write!
I am VBA-Illiterate, but thanks to all of you, and thanks to keystroke macros, I have a nice little set of routines at my disposal!
I am looking to modify one? I know what I want to do is pretty simple, so please bear with my ignorance!
I have a small macro that looks for a bookmark called ?ReportStart?, and then, it wipes out all the pages prior to that bookmark.
It?s part of a larger macro now, and works like a charm.
However, here is what I am trying to achieve:
If the user repeatedly presses this lovely ?Begin!? button (this is what we call the routine), it will keep chomping off more and more of the text since the ReportStart bookmark gets nuked!
Actually, this is what happens:
1 ? The first time the user presses the button, it works fine. It finds the bookmark, and deletes the pages of junk behind it.
2 ? If the user presses it a second time by accident, it now DELETES the bookmark(!) and takes off some text.
3 ? If the user presses it more times, it deletes more and more text.
So, this whole diatribe is basically asking the following:
?How do I make sure this little macro doesn?t do more and more damage each time the user presses it??
Any ideas are welcome!
I think I need some kind of an IF statement that says to do this routine ONLY if the ReportStart bookmark Exists, and if so, it must not be in the first position of the document!
Thanks as usual for your kind ideas!
Here you can see it surrounded by two other parts of my lovely BEGIN! macro, the first part switching to Print View, and the third part setting the zoom to 100%. (Of course these two parts have nothing to do with the question, but hey, life is all about context, right? :yes
' Put it in a nice Print View
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
' Look for the ReportStart bookmark, and delete all all the pages before it
On Error Resume Next
Selection.GoTo What:=wdGoToBookmark, Name:="ReportStart"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
If err <> 0 Then err.Clear 'clear error if needed
'Set the zoom to 100%
ActiveWindow.ActivePane.View.Zoom.Percentage = 100
Long time no write!
I am VBA-Illiterate, but thanks to all of you, and thanks to keystroke macros, I have a nice little set of routines at my disposal!
I am looking to modify one? I know what I want to do is pretty simple, so please bear with my ignorance!
I have a small macro that looks for a bookmark called ?ReportStart?, and then, it wipes out all the pages prior to that bookmark.
It?s part of a larger macro now, and works like a charm.
However, here is what I am trying to achieve:
If the user repeatedly presses this lovely ?Begin!? button (this is what we call the routine), it will keep chomping off more and more of the text since the ReportStart bookmark gets nuked!
Actually, this is what happens:
1 ? The first time the user presses the button, it works fine. It finds the bookmark, and deletes the pages of junk behind it.
2 ? If the user presses it a second time by accident, it now DELETES the bookmark(!) and takes off some text.
3 ? If the user presses it more times, it deletes more and more text.
So, this whole diatribe is basically asking the following:
?How do I make sure this little macro doesn?t do more and more damage each time the user presses it??
Any ideas are welcome!
I think I need some kind of an IF statement that says to do this routine ONLY if the ReportStart bookmark Exists, and if so, it must not be in the first position of the document!
Thanks as usual for your kind ideas!
Here you can see it surrounded by two other parts of my lovely BEGIN! macro, the first part switching to Print View, and the third part setting the zoom to 100%. (Of course these two parts have nothing to do with the question, but hey, life is all about context, right? :yes
' Put it in a nice Print View
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
' Look for the ReportStart bookmark, and delete all all the pages before it
On Error Resume Next
Selection.GoTo What:=wdGoToBookmark, Name:="ReportStart"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
If err <> 0 Then err.Clear 'clear error if needed
'Set the zoom to 100%
ActiveWindow.ActivePane.View.Zoom.Percentage = 100