• WSTroyWells

    WSTroyWells

    @wstroywells

    Viewing 15 replies - 301 through 315 (of 355 total)
    Author
    Replies
    • Thanks!! Almost home free!!

      Just one more thing: Is there some vba element that refers to this path that I could use? Since this will be done on multiple PC’s, at some point the path probably won’t be the same.

      I could probably take it from the location of

      ProgramsProgram FilesCommon FilesMicrosoft Shared

      I just don’t know how to find that in the code.

      Thanks again!!
      Troy

    • I’ve worked for an hour to try to get this work with a class module, but I guess I don’t have quite enough knowledge of the subject to get it to work. Not to mention I am running out of time to complete this project. Otherwise, I’d love to bang at it til I got it, and later, I’m sure I’ll do that.

      All I want is to add code for each programmatically added command button, and then be able to remove the code when I remove the command buttons later. The command buttons are added in a for each loop that loops through one row in a 2 dimensional array. They are added based on various list formatting characteristics found in the document. If I cancel or choose to reanalyze the document, I want to clear all the buttons (no problem) and all the associated code.

      The only thing I haven’t got to work is removing the code.

      If you could either help me get that one line of code working where I need to remove it, or add more detail to explaning how to do this in a class module, I’d appreciate it!!

      My existing code that is working except for one line is at:

      http://www.wopr.com/cgi-bin/w3t/showthread…&vc=1#Post99271

      Thanks again!!
      Troy

      P.S. I know you were excited because of your understanding in the area of class modules. I get excited when I know better ways of doing things too. However, you might just want to be careful how you express that excitement so that it doesn’t come across as disrespecting those of us that don’t have that understanding. OK, enough panking!! bash

    • Edited by TroyWells on 12-Dec-01 03:29.

      Thanks for the info!!

      I actually plan on my project being loaded as a global template. Then I would run the code from a standalone module in that global template to write code to the userform also in that global template.

      The code to add the click event code for each button works great, but I have a problem with the code to delete the code I added. See below:

      ‘This is the code I am using to add the code for the command button.
      Public GlobTemp As Template
      Public GlobTempPath As String
      Public objCurProj As VBProject
      Public FindListFormatModule As VBComponent
      ———————————————————————-
      GlobTempPath = “E:My DocumentsGoalsFormatDocuments.dot” ‘ActiveDocument.AttachedTemplate.FullName
      Set GlobTemp = Templates(GlobTempPath)
      Set objCurProj = GlobTemp.VBProject
      Set FindListFormatModule = objCurProj.VBComponents(“frmAnalyzeListFormat”)
      With FindListFormatModule.CodeModule
      .AddFromString _
      (“Public Sub MyCommandButton1_” & MyCommandButton1Number & “_Click” & vbCr _
      & “P = ” & MyCommandButton1Number & vbCr _
      & “FindListExample” & vbCr _
      & “End Sub”)
      End With

      ‘This is the code that I am using to delete the code I added above. See the note for the problem.
      Dim P As Integer
      Dim lngCodeLineCt As Integer
      lngCodeLineCt = 0
      GlobTempPath = “E:My DocumentsGoalsFormatDocuments.dot” ‘ActiveDocument.AttachedTemplate.FullName
      Set GlobTemp = Templates(GlobTempPath)
      Set objCurProj = GlobTemp.VBProject
      Set FindListFormatModule = objCurProj.VBComponents(“frmAnalyzeListFormat”)
      With FindListFormatModule.CodeModule
      For P = 1 To 1 ‘UBound(ListFormatArray, 2)
      lngCodeLineCt = lngCodeLineCt +

      ‘NOTE: The line of code below is where I am getting a “Sub or Function not defined” error.
      FindListFormatModule.CodeModule.ProcCountLines(“MyCommandButton1_” & P, vbext_pk_Proc)

      Next P
      If lngCodeLineCt > 0 Then
      FindListFormatModule.CodeModule.DeleteLines 1, Count:=lngCodeLineCt
      End If
      End With

      ONE OTHER QUESTION: based on what you said in an earlier post about the VBA Extensibility library:

      “2) Word 97 vs Word 2K – that may cause a problem. If memory serves, the one for ’97 is 5.2 and the one for 2K is 5.3. This will make things more complicated, and having never done it, all I know about it is what I’ve read here, but it may be possible to use late binding rather than set the reference during design time – i.e. have the code test for which version of Word is running, and then use CreateObject to get to the appropriate library – a topic unto itself.”

      I’ve looked at the help on this and can’t find the syntax to add a reference to the library. I have code to check the version. All I need is to add the reference. (I assume I need to do this to make sure the code that uses this library will work on other PCs. If not let me know.) Will this adding of the reference only need to happen once? I assume the addition of the reference will cause the template to want to be saved upon closing Word.

      If I can take care of these two things, I think this issue can finally be closed (with much gratitude to you for what I’ve learned along the way).

      Thanks again!!
      Troy

    • Thanks!! Don’t you love the easy ones?

      Troy

    • in reply to: Sorting an Array 3 times (VBA for Word 97/2000) #557414

      Thanks!! After making it more concise, I was able to more easily find an error that was causing it to jumble everything up.

      Troy

    • in reply to: ListType Confusion (VBA for Word 97/2000) #557393

      Edited by TroyWells on 11-Dec-01 04:13.

      This problem seems to only occur with me in Word 2000

      While I’m sure what you said is correct, try the following code:

      If ActiveDocument.Paragraphs(1).Range.ListFormat.ListType = wdListBullet Then
      MsgBox “Bullets”
      ElseIf ActiveDocument.Paragraphs(1).Range.ListFormat.ListType = wdListSimpleNumbering Then
      MsgBox “Simple”
      ElseIf ActiveDocument.Paragraphs(1).Range.ListFormat.ListType = wdListOutlineNumbering Then
      MsgBox “Outline”
      End If

      WITH the following experiment:

      1. Format > Bullets and Numbering; pick the first gallery selection under the Bulleted tab; run code.

      2. Format > Bullets and Numbering; pick the first gallery selection under the Numbered tab; run code.
      (At this point it told me I had outline numbering)

      3. Format > Bullets and Numbering; pick the first gallery selection under the Numbered tab; run code.
      (At this point it told me I had outline numbering)

      Repeat steps 1 through 3 and mix them up. See if it gives answers as inconsistently for you as it did me.

      All I want is to find out which Gallery was used to format the number (mainly whether it is bullets or numbers or none). ListType should work, but it doesn’t for me.

      Thanks!!
      Troy

    • in reply to: Sorting an Array 3 times (VBA for Word 97/2000) #557387

      I agree that a bubblesort will do me just fine and is easier to code than other examples. Thanks!!

      HOWEVER, one thing I can’t seem to get is how to swap the rows in the array.

      This is a two dimension array where the second dimension are the “rows” to be swapped.

      For example, in the example I included, the dimensions are:

      ListFormatArray(8, 12)

      So:

      ListFormatArray(1, I) would swap with ListFormatArray(1, I +1)
      ListFormatArray(2, I) would swap with ListFormatArray(2, I +1)

      I’ve made some very NON-elegant attempts at this, but it seems the values just get jumbled up. I’ve included the sample of my attempt below:

      ReDim Preserve ListFormatArray(8, 12)
      ListFormatArray(1, 1) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 1) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 1) = “18” ‘ExistingParagraphIndent
      ListFormatArray(4, 1) = ” Bordered” ‘Table Format
      ListFormatArray(5, 1) = “” ‘ComboBox1 value
      ListFormatArray(6, 1) = “” ‘ComboBox2 value
      ListFormatArray(7, 1) = “0” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 1) = “0” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 2) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 2) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 2) = “36” ‘ExistingParagraphIndent
      ListFormatArray(4, 2) = ” Bordered” ‘Table Format
      ListFormatArray(5, 2) = “” ‘ComboBox1 value
      ListFormatArray(6, 2) = “” ‘ComboBox2 value
      ListFormatArray(7, 2) = “0” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 2) = “0” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 3) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 3) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 3) = “18” ‘ExistingParagraphIndent
      ListFormatArray(4, 3) = ” Bordered” ‘Table Format
      ListFormatArray(5, 3) = “” ‘ComboBox1 value
      ListFormatArray(6, 3) = “” ‘ComboBox2 value
      ListFormatArray(7, 3) = “1” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 3) = “0” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 4) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 4) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 4) = “36” ‘ExistingParagraphIndent
      ListFormatArray(4, 4) = ” Bordered” ‘Table Format
      ListFormatArray(5, 4) = “” ‘ComboBox1 value
      ListFormatArray(6, 4) = “” ‘ComboBox2 value
      ListFormatArray(7, 4) = “1” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 4) = “0” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 5) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 5) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 5) = “18” ‘ExistingParagraphIndent
      ListFormatArray(4, 5) = ” Bordered” ‘Table Format
      ListFormatArray(5, 5) = “” ‘ComboBox1 value
      ListFormatArray(6, 5) = “” ‘ComboBox2 value
      ListFormatArray(7, 5) = “2” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 5) = “0” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 6) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 6) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 6) = “36” ‘ExistingParagraphIndent
      ListFormatArray(4, 6) = ” Bordered” ‘Table Format
      ListFormatArray(5, 6) = “” ‘ComboBox1 value
      ListFormatArray(6, 6) = “” ‘ComboBox2 value
      ListFormatArray(7, 6) = “2” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 6) = “1” ‘0 for numbers and 1 for bullets
      ‘bullets
      ListFormatArray(1, 7) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 7) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 7) = “18” ‘ExistingParagraphIndent
      ListFormatArray(4, 7) = ” Bordered” ‘Table Format
      ListFormatArray(5, 7) = “” ‘ComboBox1 value
      ListFormatArray(6, 7) = “” ‘ComboBox2 value
      ListFormatArray(7, 7) = “0” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 7) = “0” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 8) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 8) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 8) = “36” ‘ExistingParagraphIndent
      ListFormatArray(4, 8) = ” Bordered” ‘Table Format
      ListFormatArray(5, 8) = “” ‘ComboBox1 value
      ListFormatArray(6, 8) = “” ‘ComboBox2 value
      ListFormatArray(7, 8) = “0” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 8) = “1” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 9) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 9) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 9) = “18” ‘ExistingParagraphIndent
      ListFormatArray(4, 9) = ” Bordered” ‘Table Format
      ListFormatArray(5, 9) = “” ‘ComboBox1 value
      ListFormatArray(6, 9) = “” ‘ComboBox2 value
      ListFormatArray(7, 9) = “1” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 9) = “1” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 10) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 10) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 10) = “36” ‘ExistingParagraphIndent
      ListFormatArray(4, 10) = ” Bordered” ‘Table Format
      ListFormatArray(5, 10) = “” ‘ComboBox1 value
      ListFormatArray(6, 10) = “” ‘ComboBox2 value
      ListFormatArray(7, 10) = “1” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 10) = “1” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 11) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 11) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 11) = “18” ‘ExistingParagraphIndent
      ListFormatArray(4, 11) = ” Bordered” ‘Table Format
      ListFormatArray(5, 11) = “” ‘ComboBox1 value
      ListFormatArray(6, 11) = “” ‘ComboBox2 value
      ListFormatArray(7, 11) = “2” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 11) = “1” ‘0 for numbers and 1 for bullets

      ListFormatArray(1, 12) = “0” ‘ExistingNumberStyle 0 through 4
      ListFormatArray(2, 12) = “%5)” ‘ExistingNumberFormat
      ListFormatArray(3, 12) = “36” ‘ExistingParagraphIndent
      ListFormatArray(4, 12) = ” Bordered” ‘Table Format
      ListFormatArray(5, 12) = “” ‘ComboBox1 value
      ListFormatArray(6, 12) = “” ‘ComboBox2 value
      ListFormatArray(7, 12) = “2” ‘Sort number for table format 0 no 1 non 2 bordered
      ListFormatArray(8, 12) = “1” ‘0 for numbers and 1 for bullets

      ReDim Preserve ListFormatArray(8, UBound(ListFormatArray, 2) + 1)
      If UBound(ListFormatArray, 2) > 1 Then
      Dim I As Integer
      Dim BlnSorted As Boolean
      Dim strTemp As String
      BlnSorted = False
      Do Until BlnSorted
      For I = 1 To UBound(ListFormatArray, 2) – 1
      If ListFormatArray(8, I) ListFormatArray(8, I + 1) Then

      ListFormatArray(1, UBound(ListFormatArray, 2)) = ListFormatArray(1, I)
      ListFormatArray(2, UBound(ListFormatArray, 2)) = ListFormatArray(2, I)
      ListFormatArray(3, UBound(ListFormatArray, 2)) = ListFormatArray(3, I)
      ListFormatArray(4, UBound(ListFormatArray, 2)) = ListFormatArray(4, I)
      ListFormatArray(5, UBound(ListFormatArray, 2)) = ListFormatArray(5, I)
      ListFormatArray(6, UBound(ListFormatArray, 2)) = ListFormatArray(6, I)
      ListFormatArray(7, UBound(ListFormatArray, 2)) = ListFormatArray(7, I)
      ListFormatArray(8, UBound(ListFormatArray, 2)) = ListFormatArray(8, I)

      ListFormatArray(1, I) = ListFormatArray(1, I + 1)
      ListFormatArray(2, I) = ListFormatArray(2, I + 1)
      ListFormatArray(3, I) = ListFormatArray(3, I + 1)
      ListFormatArray(4, I) = ListFormatArray(4, I + 1)
      ListFormatArray(5, I) = ListFormatArray(5, I + 1)
      ListFormatArray(6, I) = ListFormatArray(6, I + 1)
      ListFormatArray(7, I) = ListFormatArray(7, I + 1)
      ListFormatArray(8, I) = ListFormatArray(8, I + 1)

      ListFormatArray(1, I + 1) = ListFormatArray(1, UBound(ListFormatArray, 2))
      ListFormatArray(2, I + 1) = ListFormatArray(2, UBound(ListFormatArray, 2))
      ListFormatArray(3, I + 1) = ListFormatArray(3, UBound(ListFormatArray, 2))
      ListFormatArray(4, I + 1) = ListFormatArray(4, UBound(ListFormatArray, 2))
      ListFormatArray(5, I + 1) = ListFormatArray(5, UBound(ListFormatArray, 2))
      ListFormatArray(6, I + 1) = ListFormatArray(6, UBound(ListFormatArray, 2))
      ListFormatArray(7, I + 1) = ListFormatArray(7, UBound(ListFormatArray, 2))
      ListFormatArray(8, I + 1) = ListFormatArray(8, UBound(ListFormatArray, 2))
      Exit For
      ElseIf ListFormatArray(7, I) ListFormatArray(7, I + 1) Then

      ListFormatArray(1, UBound(ListFormatArray, 2)) = ListFormatArray(1, I)
      ListFormatArray(2, UBound(ListFormatArray, 2)) = ListFormatArray(2, I)
      ListFormatArray(3, UBound(ListFormatArray, 2)) = ListFormatArray(3, I)
      ListFormatArray(4, UBound(ListFormatArray, 2)) = ListFormatArray(4, I)
      ListFormatArray(5, UBound(ListFormatArray, 2)) = ListFormatArray(5, I)
      ListFormatArray(6, UBound(ListFormatArray, 2)) = ListFormatArray(6, I)
      ListFormatArray(7, UBound(ListFormatArray, 2)) = ListFormatArray(7, I)
      ListFormatArray(8, UBound(ListFormatArray, 2)) = ListFormatArray(8, I)

      ListFormatArray(1, I) = ListFormatArray(1, I + 1)
      ListFormatArray(2, I) = ListFormatArray(2, I + 1)
      ListFormatArray(3, I) = ListFormatArray(3, I + 1)
      ListFormatArray(4, I) = ListFormatArray(4, I + 1)
      ListFormatArray(5, I) = ListFormatArray(5, I + 1)
      ListFormatArray(6, I) = ListFormatArray(6, I + 1)
      ListFormatArray(7, I) = ListFormatArray(7, I + 1)
      ListFormatArray(8, I) = ListFormatArray(8, I + 1)

      ListFormatArray(1, I + 1) = ListFormatArray(1, UBound(ListFormatArray, 2))
      ListFormatArray(2, I + 1) = ListFormatArray(2, UBound(ListFormatArray, 2))
      ListFormatArray(3, I + 1) = ListFormatArray(3, UBound(ListFormatArray, 2))
      ListFormatArray(4, I + 1) = ListFormatArray(4, UBound(ListFormatArray, 2))
      ListFormatArray(5, I + 1) = ListFormatArray(5, UBound(ListFormatArray, 2))
      ListFormatArray(6, I + 1) = ListFormatArray(6, UBound(ListFormatArray, 2))
      ListFormatArray(7, I + 1) = ListFormatArray(7, UBound(ListFormatArray, 2))
      ListFormatArray(8, I + 1) = ListFormatArray(8, UBound(ListFormatArray, 2))
      Exit For
      ElseIf ListFormatArray(3, I) ListFormatArray(3, I + 1) Then

      ListFormatArray(1, UBound(ListFormatArray, 2)) = ListFormatArray(1, I)
      ListFormatArray(2, UBound(ListFormatArray, 2)) = ListFormatArray(2, I)
      ListFormatArray(3, UBound(ListFormatArray, 2)) = ListFormatArray(3, I)
      ListFormatArray(4, UBound(ListFormatArray, 2)) = ListFormatArray(4, I)
      ListFormatArray(5, UBound(ListFormatArray, 2)) = ListFormatArray(5, I)
      ListFormatArray(6, UBound(ListFormatArray, 2)) = ListFormatArray(6, I)
      ListFormatArray(7, UBound(ListFormatArray, 2)) = ListFormatArray(7, I)
      ListFormatArray(8, UBound(ListFormatArray, 2)) = ListFormatArray(8, I)

      ListFormatArray(1, I) = ListFormatArray(1, I + 1)
      ListFormatArray(2, I) = ListFormatArray(2, I + 1)
      ListFormatArray(3, I) = ListFormatArray(3, I + 1)
      ListFormatArray(4, I) = ListFormatArray(4, I + 1)
      ListFormatArray(5, I) = ListFormatArray(5, I + 1)
      ListFormatArray(6, I) = ListFormatArray(6, I + 1)
      ListFormatArray(7, I) = ListFormatArray(7, I + 1)
      ListFormatArray(8, I) = ListFormatArray(8, I + 1)

      ListFormatArray(1, I + 1) = ListFormatArray(1, UBound(ListFormatArray, 2))
      ListFormatArray(2, I + 1) = ListFormatArray(2, UBound(ListFormatArray, 2))
      ListFormatArray(3, I + 1) = ListFormatArray(3, UBound(ListFormatArray, 2))
      ListFormatArray(4, I + 1) = ListFormatArray(4, UBound(ListFormatArray, 2))
      ListFormatArray(5, I + 1) = ListFormatArray(5, UBound(ListFormatArray, 2))
      ListFormatArray(6, I + 1) = ListFormatArray(6, UBound(ListFormatArray, 2))
      ListFormatArray(7, I + 1) = ListFormatArray(7, UBound(ListFormatArray, 2))
      ListFormatArray(8, I + 1) = ListFormatArray(8, UBound(ListFormatArray, 2))
      Exit For
      End If

      If I = UBound(ListFormatArray, 2) – 1 Then
      BlnSorted = True
      End If
      InextI:
      Next I
      Loop
      ReDim Preserve ListFormatArray(8, UBound(ListFormatArray, 2) – 1)
      End If

      MsgBox ListFormatArray(8, 1) & “, ” & ListFormatArray(7, 1) & “, ” & ListFormatArray(3, 1)
      MsgBox ListFormatArray(8, 2) & “, ” & ListFormatArray(7, 2) & “, ” & ListFormatArray(3, 2)
      MsgBox ListFormatArray(8, 3) & “, ” & ListFormatArray(7, 3) & “, ” & ListFormatArray(3, 3)
      MsgBox ListFormatArray(8, 4) & “, ” & ListFormatArray(7, 4) & “, ” & ListFormatArray(3, 4)
      MsgBox ListFormatArray(8, 5) & “, ” & ListFormatArray(7, 5) & “, ” & ListFormatArray(3, 5)
      MsgBox ListFormatArray(8, 6) & “, ” & ListFormatArray(7, 6) & “, ” & ListFormatArray(3, 6)
      MsgBox ListFormatArray(8, 7) & “, ” & ListFormatArray(7, 7) & “, ” & ListFormatArray(3, 7)
      MsgBox ListFormatArray(8, 8) & “, ” & ListFormatArray(7, 8) & “, ” & ListFormatArray(3, 8)
      MsgBox ListFormatArray(8, 9) & “, ” & ListFormatArray(7, 9) & “, ” & ListFormatArray(3, 9)
      MsgBox ListFormatArray(8, 10) & “, ” & ListFormatArray(7, 10) & “, ” & ListFormatArray(3, 10)
      MsgBox ListFormatArray(8, 11) & “, ” & ListFormatArray(7, 11) & “, ” & ListFormatArray(3, 11)
      MsgBox ListFormatArray(8, 12) & “, ” & ListFormatArray(7, 12) & “, ” & ListFormatArray(3, 12)

      Thanks again for your help!!
      Troy

    • Thanks again for the help!!

      However, I am still getting kicked out at line of code where I set the MODULE as the userform module. This is the specific line of code:

      Set FindListFormatModule = objCurrProj.VBComponents(“frmAnalyzeListFormat”)

      I’ve also tried:

      Set frmAnalyzeListFormat = objCurrProj.VBComponents(“frmAnalyzeListFormat”)

      Both times I get kicked out of the sub at this point.

      Perhaps there is something I’m not dimming properly or setting? I’ve included the entire block of code. This is all I have related to adding this code. Let me know if I’m missing something here. Am I supposed to set objCurrProj = to something?

      Dim FindListFormatModule As VBComponent
      Dim objCurrProj As VBProject
      Set FindListFormatModule = objCurrProj.VBComponents(“frmAnalyzeListFormat”)
      With FindListFormatModule.CodeModule
      .AddFromString _
      (“Public Sub MyCommandButton1_” & MyCommandButton1Number & “_Click” & vbCr _
      & “P = ” & MyCommandButton1Number & vbCr _
      & “FindListExample” & vbCr _
      & “End Sub”)
      End With

      Thanks!!
      Troy

    • Thanks for your patience and time. I really appreciate it, and am learning a lot!! clapping

      I do have some followup to your responses as follows:

      1) Thanks!! I think I’ve got it.

      2) I’ll check that out.

      3) You say “modDynCode” is the module you setup manually. I assume by that you mean you created an empty module by that name. I did the same name, although the name I gave it probably gave you the impression that it was the name of a procedure.

      You say “you would want to use the name of the userform’s module.” By that do you mean the module that appears when you right-click on the form in Project Explorer and click “View Code”? That would make sense to me. However, how do you reference that? Do you have to dim it as something and/or set it as something? I couldn’t figure out how to access that.

      4) No the form is already created. I am only resizing the form as I go and adding controls. Also, as I said for #3 above, I am referencing a module, but it is a stand alone module, not the module for the userform. I think if you can help me reference the correct module, that will take care of my problems.

      Thanks again!!
      Troy

    • Edited by TroyWells on 08-Dec-01 20:02.

      That sounds great, but have a few questions:

      1) I found this library by going to Tools/References and selected “Microsoft Visual Basic for Applications Extensibility 5.3”, but I don’t see that it added anything to my References folder for the project. Should it be?

      2) Also, there is one thing I forgot to tell you that may or may not affect anything: I need this to work with BOTH Word 97 and Word 2000. Any problems?

      3) Is FindListFormatProcedure in my code below (same as modDynCode in your code) supposed to be the name of the module containing these click events or is this somehow automatically added to userform’s (in my case frmAnalyzeListFormat) code?

      4)The following is the code that I added. NOTE the line of code that kicks me out of the sub where I add the button code. NOTE also the line of code the errors when removing the code:

      ‘As the button is created I am adding code for that button. This made things much simpler.
      Set MyCommandButton1 = frmAnalyzeListFormat.Controls.Add(“Forms.CommandButton.1”, “MyCommandButton1_” & MyCommandButton1Number)
      MyCommandButton1.Height = 18
      MyCommandButton1.Width = 45
      MyCommandButton1.Top = PreviousLabelRowHeight + 17
      MyCommandButton1.Left = 282
      MyCommandButton1.Caption = “Show Me”
      ‘Add code for click event.
      Dim FindListFormatProcedure As VBComponent
      Dim objCurrProj As VBProject
      ‘ Set objCurrProj = ActiveDocument
      ****************************************************************
      ‘The following line of code kicks me out of the sub:
      Set FindListFormatProcedure = objCurrProj.VBComponents(“FindListFormatProcedure”)
      *********************************************************************
      With FindListFormatProcedure.CodeModule
      .AddFromString _
      (“Public Sub MyCommandButton1_” & MyCommandButton1Number & “_Click” & vbCr _
      & “P = ” & MyCommandButton1Number & vbCr _
      & “FindListExample” & vbCr _
      & “End Sub”)
      End With
      ******************************

      The following code I put in other events (such as the click event of a Cancel button I have) to delete the code:
      Dim FindListFormatProcedure As VBComponent
      Dim objCurrProj As VBProject
      Dim lngCodeLineCt As Integer
      ‘Set objCurrProj = ActiveDocument
      **********************************************
      ‘The following 2 lines of code gives me an “Object variable or With block variable not set” error.
      Set FindListFormatProcedure = objCurrProj.VBComponents(“FindListFormatProcedure”)
      With FindListFormatProcedure.CodeModule
      *******************************************************
      ‘first delete any existing code.
      lngCodeLineCt = FindListFormatProcedure.CodeModule.CountOfLines
      If lngCodeLineCt > 0 Then
      FindListFormatProcedure.CodeModule.DeleteLines 1, Count:=lngCodeLineCt
      End If
      End With

      Thanks for all your help!!
      Troy

    • in reply to: If Then Else not working (VBA for Word 2000) #555443

      Believe it or not, the problem was another “End If” that I had commented out. If found it after moving a large block of code within this procedure to its own procedure.

      I hate it when it’s something simple.

      Thanks for responding!!
      Troy brickwall

    • in reply to: Help with Procedure (Word 2000 VBA) #553975

      That last bit of advice did the trick. The following is the code related that I used successfully (including a message box to see that it worked):

      ‘find %#within the string.
      Dim NumFormatPos, NumFormatCharacter, NumFormatString
      NumFormatPos = InStr(ExistingNumberFormat, “%”) + 1
      NumFormatCharacter = Mid(ExistingNumberFormat, NumFormatPos, 1)
      ExistingListFormat = Replace(ExistingNumberFormat, “%” & NumFormatCharacter, ExistingNumberStyleExample)
      MsgBox ExistingListFormat

      Thanks as always for your help and patience!!
      Troy

    • in reply to: Help with Procedure (Word 2000 VBA) #553948

      What you have there does work for me. The problem is that I don’t know what the number is going to be after the “%”. Thus have been trying to use the folloing code, assuming that if the search string is not found, it is not replaced:

      ExistingListFormat = Replace(ExistingNumberFormat, “%1”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “%2”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “%3”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “%4”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “%5”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “%6”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “%7”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “%8”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “%9”, ExistingNumberStyleExample)

      If I just pick the right line of code (and comment out the rest) it works fine, but since I don’t know which one this will be I have been stepping through all of these lines.

      Any ideas how I can handle each of the possible cases above? If there was just a way that tell when a replace has occurred, I could skip the remaining steps.

      Thanks for any help you can give!! Enjoy the leftovers!!
      Troy

    • in reply to: Help with Procedure (Word 2000 VBA) #553765

      Edited by TroyWells on 24-Nov-01 05:38.

      Sorry I forgot to explain that last time. There should be “1%” or “2%”…”9%” in the string. Because I don’t know which one, I’m searching for all of them. I assumed that that if it did not find the search string, it would not do anything to the string in which it was searching. Perhaps that is a bad assumption. This was one of the rare cases I have found that the online help did not provide as much information or an example.

      Perhaps I could set a variable for this to reduce the number of search or replaces. It would great if I could use a wildcard for “any digit”.

      NEW: I wanted to include an example of what I am searching.

      The value I am searching could be “(%1)” where I would replace “%1” with a value such as “a”.
      The value I am searching could be “%1.” where I would replace “%1” with a value such as “1”.

      Thanks again for all your help!! Hope you have a great Thanksgiving!!
      Troy

    • in reply to: Help with Procedure (Word 2000 VBA) #553544

      Thanks to both Klaus and Gary for your help!!

      One outstanding issue:
      ExistingListFormat = Replace(ExistingNumberFormat, “1%”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “2%”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “3%”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “4%”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “5%”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “6%”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “7%”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “8%”, ExistingNumberStyleExample)
      ExistingListFormat = Replace(ExistingNumberFormat, “9%”, ExistingNumberStyleExample)

      I swapped this around, but it still does not seem to be doing anything. What I am trying to do is look for the %# in the .NumberFormat and replace it with the ExistingNumberStyleExample value. The result would be like “1.” or “a)”. Instead I am still seeing ExistingListFormat as “%1.” To further explain, I am trying to get an example of exactly what is on the screen for this number format.

      In addition, let me give you the big picture (I purposefully left this out before because I wanted to continue figuring this out on my own as much as possible for learning purposes. But now I think I’ve learned all I can on this without help.). I am wanting to populate a form with a row of items for each distinct number format and left indent. The row will consist of a label for the number format, label for the left indent, and two combo boxes filled with valid choices for the number format and left indent. Basically I want to standardize a nonstandard document, but with the flexibility for the user to define what existing number formats are.

      I have attached a document with the form and code. BE AWARE I know the code isn’t totally finished. THe main thing I know it is missing is the code for positioning each label and combobox. I think I can handle that part, so don’t worry about adding that in. Please let me know if there is another better way of going about what I am doing.

      P.S. In case it looked familier, I based some of the logic for this on a procedure I got from here from you, Gary, for finding unused styles.

    Viewing 15 replies - 301 through 315 (of 355 total)