Re: Macro Help Please
From: Jezebel (dwarves_at_heaven.com.kr)
Date: 10/25/04
- Previous message: Steved: "Macro Help Please"
- In reply to: Steved: "Macro Help Please"
- Next in thread: Steved: "Re: Macro Help Please"
- Reply: Steved: "Re: Macro Help Please"
- Messages sorted by: [ date ] [ thread ]
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.
- Previous message: Steved: "Macro Help Please"
- In reply to: Steved: "Macro Help Please"
- Next in thread: Steved: "Re: Macro Help Please"
- Reply: Steved: "Re: Macro Help Please"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|