UserForm

D

discostu1975

I am working on a userform that will distribute the inputted information to
bookmarks in a word document. This part works flawlessly. Once the userform
has been filled out I am presented with Document1 that has all of the updated
information in about 5 sections. The UserForm is called from a macro called
AutoNew in which the only code is Show UserForm1

I have a macro (BreakOnSection) that I can run that will then take each of
the sections and save them as separate files to any specified location. This
too works flawlessly when called from within a document.

What I would like to have happen is once the user clicks my control button
in UserForm1, it will do both of the above processes so that it eliminates
the need for them to run the macro separately.

I have tried to copy the text of the BreakOnSection Macro directly into the
command button and I've tried to do a call to it (as illustrated below).
I've even tried to incorporate it as part of AutoNew. The problem is that
I'm not getting any error messages right now but the macro is not running.

I snipped out a bunch of the bookmark moves, but have included the remainder
of the code.



Private Sub CommandButton1_Click()
With ActiveDocument
..Bookmarks("purchaser").Range _
..InsertBefore purchaser
..Bookmarks("purchaser2").Range _
~snip~
End With
Call BreakOnSection
UserForm1.Hide


End Sub


Here is the macro text too



Sub BreakOnSection()
' Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection

'A mailmerge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)

'Select and copy the section text to the clipboard
ActiveDocument.Bookmarks("\Section").Range.Copy

'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste

' Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1

ChangeFileOpenDirectory "C:\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.Close
' Move the selection to the next section in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Userform 4
Macro Loop 0
Userform 1
Document Merge Formatting Issue 0
Select Text to End of Footnote 9
Loop 2
Section and Page numbering 0
Loop until end 1

Top