B
bufuro
Hi. I made a macro in Microsoft Word.
But I need to create a VBA which does the macro.
So what I have to create is, make a program that imports user's word
document, and run the macro.
Can any of you help me on this? I mean how can I transform the macro into
VBA?
following is my macro.
----------------------------
Sub breakapart()
' splitter Macro
Dim mask As String
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
mask = "ddMMyy"
Selection.HomeKey Unit:=wdStory
Counter = 1
FileId = " "
FileId2 = " "
While Counter < Letters
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
FileId = Selection
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
FileId2 = Selection
DocName = "C:\Progress Report\students\" & FileId
DocName2 = "C:\Progress Report\advisors\" & FileId2
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument
ActiveWindow.Close
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=DocName2, FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Wend
End Sub
But I need to create a VBA which does the macro.
So what I have to create is, make a program that imports user's word
document, and run the macro.
Can any of you help me on this? I mean how can I transform the macro into
VBA?
following is my macro.
----------------------------
Sub breakapart()
' splitter Macro
Dim mask As String
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
mask = "ddMMyy"
Selection.HomeKey Unit:=wdStory
Counter = 1
FileId = " "
FileId2 = " "
While Counter < Letters
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
FileId = Selection
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
FileId2 = Selection
DocName = "C:\Progress Report\students\" & FileId
DocName2 = "C:\Progress Report\advisors\" & FileId2
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument
ActiveWindow.Close
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=DocName2, FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Wend
End Sub