Re: Macro Help Please

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jezebel (dwarves_at_heaven.com.kr)
Date: 10/25/04

  • Next message: Steved: "Re: Macro Help Please"
    Date: Mon, 25 Oct 2004 16:17:27 +1000
    
    

    You need to add the Scripting library to your project. In VBA, go to Tools >
    References and select 'Microsoft Scripting Runtime'. This library tells VBA
    what 'Scripting' means in your application, which in turn defines
    'dictionary'.

    Before you do this, however, consider using a collection object instead.
    This is built-in and does almost everything that the dictionary object will
    do anyway. Adding *any* references to your project makes distribution more
    difficult if you want others to use your macro. And the Scripting object in
    particular is a notorious cause of problems: a) it has bugs, b) it's
    unstable, and c) there are security issues such that some users disable it
    completely (in which case, your macro won't work).

    "Steved" <anonymous@discussions.microsoft.com> wrote in message
    news:11d101c4ba56$ee39dda0$a301280a@phx.gbl...
    > Hello From Steved Please help me I am trying to get to
    > understand word macros.
    >
    > Dict As Scripting.Dictionary
    > This macro highlights the above when doing an F8
    > and displays
    > compile error
    > User-defined type not defined
    >
    >
    > Sub Macro1()
    > '
    > ' Macro1 Macro
    >
    > '
    >
    > ' trying to open dictionary file
    > Dim DictFile As String
    > DictFile = form.Dictionary_TextBox.Text
    > If "" = DictFile Then
    > MsgBox "Dictionary file name is empty!"
    > Stop
    > End If
    > Documents.Open FileName:=DictFile
    >
    > Dim Dict As Scripting.Dictionary
    > Set Dict = New Scripting.Dictionary
    >
    > Dim str As String
    > Dim Strings As Variant
    >
    > For i = 1 To ActiveDocument.Paragraphs.Count
    > str = ActiveDocument.Paragraphs(i).Range.Text
    > Strings = Split(str, "=")
    > Entry = UCase(Strings(0))
    > Item = UCase(Strings(1))
    > Dict.Add Entry, Item
    > Next i
    >
    > ' trying to open source file
    > Dim SourceFile As String
    > SourceFile = form.Src_TextBox.Text
    > If "" = SourceFile Then
    > MsgBox "Source file name is empty!"
    > Stop
    > End If
    > Documents.Open FileName:=SourceFile
    > Dim NumOfEntries As Integer
    > NumOfEntries = ActiveDocument.Paragraphs.Count / 2
    >
    > With ActiveDocument
    > For n = 2 To NumOfEntries * 4 Step 4
    > Dim key As String
    > key = ""
    > ' get the name assuming that its length no more
    > ' than 18 chars and starts at 11th position and
    > ends on 28th maximum
    > With .Paragraphs(n - 1).Range
    > For i = 11 To 29
    > key = key + .Characters(i)
    > Next i
    > End With
    > key = RTrim(key)
    > .Paragraphs(n).Range.InsertParagraphAfter
    > Dim Value As String
    > Value = Dict.Item(key)
    > If Value = "" Then
    > Value = "NEW"
    > .Paragraphs(n).Range.InsertParagraphAfter
    > End If
    > .Paragraphs(n).Range.InsertAfter " " + Value
    > Next n
    > End With
    >
    > End Sub
    >
    > Thankyou.


  • Next message: Steved: "Re: Macro Help Please"

    Relevant Pages

    • Re: Execute macro for all documents in the folder
      ... You can start by using the macro recorder and examining the code to see what ... It is simple enough to batch process a single folder. ... Dim strFileName As String ...
      (microsoft.public.word.docmanagement)
    • Re: Document Property to display more than 1 line
      ... then use the following macro to identify the character ... Dim strNums As String ...
      (microsoft.public.word.newusers)
    • Re: Form refresh code
      ... Your version of the InserrtAddress macro also unlocked the field with the ... string variable name in the protect/unprotect commands. ... Public Sub InsertAddressFromOutlook() ... Dim strCode As String, strAddress As String ...
      (microsoft.public.word.docmanagement)
    • Re: Form refresh code
      ... Are you aware when running the macro the cursor runs to every form ... Sub ResetForm() ... Dim oFld As FormFields ... Dim sQuery As String ...
      (microsoft.public.word.docmanagement)
    • Re: condition formula in Word 2003
      ... It includes a macro to reset the address. ... Sub AutoNew() ... Dim SettingsFile As String ...
      (microsoft.public.word.docmanagement)