• WSTroyWells

    WSTroyWells

    @wstroywells

    Viewing 15 replies - 316 through 330 (of 355 total)
    Author
    Replies
    • in reply to: Crashin’ VB Program (VB6(SP5) & Word 2000(SP1)) #551239

      I’m certain no VB expert, but I’m learning. I came across a similar problem on a VBA application I was building.

      For me it ended up being some corruption. I was able to overcome it by exporting all my forms and modules, and then reimporting them into a new document (importing into a new project for VB, I guess).

      Hope that helps!!
      Troy

    • in reply to: Populating text box based on option button (Word 2000 VBA) #549028

      I can’t believe it was that simple. Yes, moving the UserForm1.Show to the last step solved my problem.

      F.Y.I., the reason I was using variables is simply because they already existed and are set by the click event on the object buttons for other reasons within the larger application (which I did not include in the sample).

      Thanks so much for your help!!
      Troy blush

    • in reply to: Insert a document object with relative path (Word 2000 VBA) #547896

      I wanted to reply for the information of others, since I found this answer on another newsgroup.

      From “Cindy Meister -WordMVP-” <CindyMeister@swissonline.ch

      It's quite understandable why a method that inserts an object
      wants to have a full path. Is your issue picking up the file
      from a relative location? Then use ActiveDocument.Path & "" &
      "Filename"

      So the new code that works for me is:

      Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8", FileName _
      :=ActiveDocument.Path & "" & "Object.doc", LinkToFile:=False, DisplayAsIcon _
      :=False

      Enjoy!!
      Troy

    • in reply to: Exiting a Parent sub from a child sub (Word 2000 VBA) #545141

      What I was doing was bringing up a message box and deselecting a check box if one of three option buttons was not selected (they all start out false). The key to getting this down was your idea that setting the check box value to false was initiating the Click event. That is exactly what was happening. The following is my solution. Feel free to improve upon it, but this does work as I had hoped.

      NOTE: I did not include the function (which I changed to a sub) called “IsDocumentTypeSelected”. This function set’s a variable (DocumentTypeSelected) if it determines that none of the option buttons have been set to True.

      Private Sub cbxAddCoverCopyright_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
      IsDocumentTypeSelected
      If DocumentTypeSelected = False Then
      MsgBox “You must select a document type before setting options.”
      Cancel = True
      Exit Sub
      End If
      End Sub

      Private Sub cbxAddCoverCopyright_Click()
      If cbxAddCoverCopyright.Value = True Then
      frmOptionsCoverCopyright.Show
      PopulateCoverOptionControlsFromVariables
      End If
      End Sub

      By using the MouseDown event to check the status of the variable, I did not even have to set the checkbox value to false. I could then follow this with the Click event if the variable was true. For some strange but wonderful reason, if the MouseDown event found the variable to be false, the Click event never happened.

      Thanks for all the help!!
      Troy

    • in reply to: Exiting a Parent sub from a child sub (Word 2000 VBA) #545036

      I guess I should have mentioned that this is but a small piece of a much larger project. The variable you mentioned is a public boolean variable in a separate module. I just forgot to include it with the code I posted.

      I’ll take into consideration getting rid of the “Set”. Thanks for the insightful input!!

      The main issue now is getting only one instance of the message box to show up. Everything else seems to work.

      Thanks for your help!!
      Troy

    • in reply to: Exiting a Parent sub from a child sub (Word 2000 VBA) #545015

      I’m fairly new at this stuff so bear with me. I’ll try to answer your questions amidst the code below:

      Private Sub cbxAddCoverCopyright_Click()

      ‘The following line of code is where I am calling the function for the first (and I thought only) time.
      SetDocumentType

      ‘The following line of code is where I am setting getting the Result of the function.
      Result = SetDocumentType()

      ‘Next I use the result in an If..Then statement.
      If Result = False Then

      “cbxAddCoverCopyright” is a check box. If setting the value to false is considered a click, HOW DO I GET AROUND THAT?

      cbxAddCoverCopyright.Value = False
      MsgBox “You must select a document type before setting options.”
      Cancel = True
      Exit Sub
      End If
      ….
      End Sub
      ——————————————————————————–
      Public Function SetDocumentType()
      If frmFormatDocumentMain.obBusinessDocument.Value = False And _
      frmFormatDocumentMain.obTechnicalDocument.Value = False And _
      frmFormatDocumentMain.obUserDocument.Value = False Then
      SetDocumentType = False
      End If
      End Function

      Thanks again for your help!!
      Troy

    • in reply to: Exiting a Parent sub from a child sub (Word 2000 VBA) #544971

      That seems to work fine (and thanks so much for pointing my in the right programming direction), EXCEPT why would my MsgBox appear twice? I have to click OK or hit ENTER twice to get rid of it. I have included the code I am using below.

      Thanks again for your help!!
      Troy

      Private Sub cbxAddCoverCopyright_Click()
      SetDocumentType
      Result = SetDocumentType()
      If Result = False Then
      cbxAddCoverCopyright.Value = False
      MsgBox “You must select a document type before setting options.”
      Cancel = True
      Exit Sub
      End If
      ….
      End Sub
      ——————————————————————————–
      Public Function SetDocumentType()
      If frmFormatDocumentMain.obBusinessDocument.Value = False And _
      frmFormatDocumentMain.obTechnicalDocument.Value = False And _
      frmFormatDocumentMain.obUserDocument.Value = False Then
      SetDocumentType = False
      End If
      End Function

    • F.Y.I. just in case this happens to you, I thought I would share what appears to be the fix for this, even though I don’t know for sure the cause. Perhaps there was some document corruption.

      I ended up exporting all my forms and modules, and then importing them into a new clean document. The new document does not exhibit the errors of the other document.

      Hope this helps someone else!!
      Troy

    • in reply to: Adding all headings to a list box (VBA for Word 2000) #543106

      That did the trick. Thanks!!

      I actually can get out of testing if I am in the heading by going to the very end of the document

      Selection.EndKey Unit:=wdStory

      and then running this code. Since the last item in the document is not likely to be a heading (unlike the first item), this code should work just fine.

      Thanks again for the help!!
      Troy

    • in reply to: Adding all headings to a list box (VBA for Word 2000) #543077

      Yes!! You were exactly right. I changed this in one of my fruitless attempts to get my code to work and forgot to change it back. It works fine now.

      However, now that my list box contains the lists, I cannot seem to do the next step. I want to find (and select) the selected item (heading) in the list after I click OK. I have tried the following code, but it does not seem to work.

      Private Sub cmbOK_Click()
      Dim i As Integer
      For i = lbAppxHeadings.ListCount – 1 To 0 Step -1
      If lbAppxHeadings.Selected(i) = True Then
      Selection.GoTo What:=wdGoToHeading, Which:=wdGoToAbsolute, Count:=i
      Exit For
      End If
      Next i
      End Sub

      Thanks for any help you can give!!
      Troy

    • in reply to: Adding all headings to a list box (VBA for Word 2000) #542887

      This is what I am trying, but still I get nothing:

      Private Sub frmAppendixStartsat_Initialize()
      Dim DocumentHeadings As Variant, i As Integer
      DocumentHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading)
      For i = 1 To UBound(DocumentHeadings)
      lbAppxHeadings.AddItem DocumentHeadings(i)
      Next i
      End Sub

      What am I missing?

      Thanks again!!
      Troy

    • in reply to: Adding all headings to a list box (VBA for Word 2000) #542868

      Thanks again for your response. Unfortunately, that code doesn’t seem to do anything.

      Also, to answer your question, the main thing I need to do after I select a heading and click OK is to find that particular heading. Once found I will format the heading with a specific style, adjust numbering, etc. If I can just populate the list, select the heading and then find it, I can take it from there.

      Thanks!!
      Troy

    • in reply to: Adding all headings to a list box (VBA for Word 2000) #542830

      Thanks for your reply. I found the statement:

      myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading)

      but could never figure out how to use it properly to collect all the headings and put them in a list. I will need to select a heading and then perform some functions on it afterward. I probably am just lacking the syntax to do this properly. I’m very much a newbie when it come to arrays as well. This may be part of my problem.

      Regarding:

      Selection.GoTo What:=wdGoToHeading, Which:=wdGoToNext, count:=1, Name:=””

      I still need to understand what to do to populate my list box. I would also need to make sure I could find it again later to perform the functions I need to on what I select.

      Thanks again for your help!!
      Troy

    • This did the trick. I learned a lot through studying your code and making a few modifications here and there. Thanks for taking the time!!

      Troy

    • Thanks so much for your response. This did work for me. bow

      However, as I am in learning mode, I did have a couple of questions and one additional request scratch:

      Question 1: What is the purpose or function of the following line in the code you gave me:

      q = Int(AlphaNumber / 26)

      Question 2: What is the purpose or function of the following line in the code you gave me:

      TextBox2.Value = Chr(64 + q) & Chr(65 + AlphaNumber – q * 26)

      Request 1: As much as I appreciated your suggestions for disabling the text box for user input, I actually want users to be able to manually input, as well as use spinbuttons. However, when I tried to do this using the code you gave below (I only changed the variable names to protect the somewhat innocent) and then used a spin button, it only accepted the value of the spinbutton. I tried putting the following code in the change event for the text box:

      SpinButton1.Value=TextBox1.Value

      but that didn’t seem to do anything. If you could provide this extra bit of information, I’d sure appreciate it.

      Thanks!!
      Troy

    Viewing 15 replies - 316 through 330 (of 355 total)