Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

How can I make VBA to run Microsoft word macro?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bufuro - 13 Mar 2005 17:29 GMT
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
Howard Kaikow - 13 Mar 2005 19:22 GMT
The macro is VBA.

Signature

http://www.standards.com/; See Howard Kaikow's web site.

> Hi.  I made a macro in Microsoft Word.
>
[quoted text clipped - 61 lines]
>
> End Sub
bufuro - 14 Mar 2005 00:23 GMT
Then can I copy the macro code to Visual Basic .NET and make a program?
Don't I need to import somekind of microsoft word reference?
> The macro is VBA.
>
[quoted text clipped - 65 lines]
>>
>> End Sub
Howard Kaikow - 14 Mar 2005 06:51 GMT
Moving VBA code to either VB or VB .NET requires learning a bit about
Automating Word from another app.

You have to ask at least the following questions:

1. Is the goal to create a library of code that can be referenced from
within Word?
2. Is the goal to have a stand-alone program that controls Word?

Signature

http://www.standards.com/; See Howard Kaikow's web site.

> Then can I copy the macro code to Visual Basic .NET and make a program?
> Don't I need to import somekind of microsoft word reference?
[quoted text clipped - 67 lines]
> >>
> >> End Sub
bufuro - 16 Mar 2005 01:18 GMT
I think my goal is to have a stand-alone program.  Is that possible?

(Thank you so much for all your help)

> Moving VBA code to either VB or VB .NET requires learning a bit about
> Automating Word from another app.
[quoted text clipped - 79 lines]
>> >>
>> >> End Sub
Howard Kaikow - 16 Mar 2005 06:07 GMT
There is not really such a thing as a stand-alone Word program.

But, you can write your program in, e.g, VB 6 or VB .NET, and control Word
from that program.

For example, the following is a VB 6 program that works in Word 97 and up
that uses Word and Excel. In this case, neither Word nor Excel is made
visible to the user.

http://www.standards.com/index.html?Sorting

In another app, the VB program could act as a front-end for starting, say,
word or Excel, and, as needed, cleanup after itself.

Or you could put the code in a DLL and Word can use the code in the DLL.

For example, the following is ALL the code in my Normal template, all the
real code is in a number of VB 6 compiled DLLs:

Option Explicit
Public clsWordVBNormal As WordVBNormal

Public Sub AutoClose()
   SetupClass
   clsWordVBNormal.AutoClose
End Sub

Public Sub AutoExec()
   ' Runs only when global
   SetupClass
   clsWordVBNormal.AutoExec
End Sub

Public Sub AutoExit()
   SetupClass
   clsWordVBNormal.AutoExit
End Sub

Public Sub AutoNew()
   SetupClass
   clsWordVBNormal.AutoNew
End Sub

Public Sub AutoOpen()
   SetupClass
   clsWordVBNormal.AutoOpen
End Sub

Private Sub SetupClass()
   Dim docTemp As Word.Document
   If clsWordVBNormal Is Nothing Then
       If Documents.Count = 0 Then
           Set docTemp = Documents.Add(Visible:=vbFalse)
       End If
       Set clsWordVBNormal = New WordVBNormal
       clsWordVBNormal.SetClass Word.Application
       If Not (docTemp Is Nothing) Then
           docTemp.Close
           Set docTemp = Nothing
       End If
   End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit

Public Sub ResetToolsOptionsView()
   clsWordVBNormal.ResetToolsOptionsView
End Sub

Signature

http://www.standards.com/; See Howard Kaikow's web site.

> I think my goal is to have a stand-alone program.  Is that possible?
>
[quoted text clipped - 83 lines]
> >> >>
> >> >> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.