View Single Post
 
Old 05-04-2012, 12:17 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,383
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 Randy,

OK, if the useform & command button show, the code behind them should be there also. In that case, try adding something like:
MsgBox "!"
at different points in the code so that you can see where is runs to.

Instead of your latest sub, try:
Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim Scn As Section, Rng As Range, Doc As Document
Dim StrPath As String, StrName As String
StrPath = "E:\Documents and Settings\" & Environ("UserName") & "\Desktop\EMS\"
If Dir(StrPath, vbDirectory) = "" Then
  MkDir StrPath
End If
For Each Scn In ActiveDocument.Sections
  Set Rng = Scn.Range
  With Rng
    .End = .End - 1
    .Copy
  End With
  Set Doc = Documents.Add
  With Doc
    .Range.Paste
    Set Rng = .Range.Paragraphs.First
    With Rng
      .End = .End - 1
      StrName = .Text
    End With
    .SaveAs FileName:=StrPath & StrName & ".docx", AddToRecentFiles:=False
    .Close
  End With
Next
Set Rng = Nothing: Set Doc = Nothing
Application.ScreenUpdating = True
End Sub
This should save each Section in your active document as a new file in the target folder, which will be created if it doesn't already exist.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote