Avatar billede doktoren001 Juniormester
05. oktober 2009 - 13:34 Der er 1 løsning

VB i Word ComboBox

Hej,

Jeg har et problem med et få nogle valgmuligheder ind i to combobox´e i word!
Når jeg dobbelt klikker på den skabelon jeg har lavet kommer min "popup" box fint frem men der er ikke noget i de to combobox´e.

Jeg håber at der er nogle der kan hjælpe :-)

--->

Const f1 = "<chapter>"
Const f2 = "<category>"


Private Sub CommandButton1_Click()                  'OK
    If Me.ComboBox1 <> "" And Me.ComboBox2 <> "" Then
Rem navn - adresse - postnr by
        søgErstatTekst f1, Me.ComboBox1
        søgErstatTekst f2, Me.ComboBox2
     
    Else
        MsgBox ("Both input areas must be filled out!")
    End If
    Unload UserForm1
End Sub



Public Sub søgErstatTekst(sTekst, eTekst)
  Dim rngStory As Word.Range
  Dim pFindTxt As String
  Dim pReplaceTxt As String
  Dim lngJunk As Long
  Dim oShp As Shape
  pFindTxt = sTekst
  If pFindTxt = "" Then
    MsgBox "Cancelled by User"
    Exit Sub
  End If
TryAgain:
  pReplaceTxt = eTekst
  If pReplaceTxt = "" Then
    If MsgBox("Do you just want to delete the found text?", _
    vbYesNoCancel) = vbNo Then
      GoTo TryAgain
    ElseIf vbCancel Then
      MsgBox "Cancelled by User."
      Exit Sub
    End If
  End If
  'Fix the skipped blank Header/Footer problem
  lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
  'Iterate through all story types in the current document
  For Each rngStory In ActiveDocument.StoryRanges
    'Iterate through all linked stories
    Do
      SearchAndReplaceInStory rngStory, pFindTxt, pReplaceTxt
      On Error Resume Next
      Select Case rngStory.StoryType
      Case 6, 7, 8, 9, 10, 11
        If rngStory.ShapeRange.Count > 0 Then
          For Each oShp In rngStory.ShapeRange
            If oShp.TextFrame.HasText Then
              SearchAndReplaceInStory oShp.TextFrame.TextRange, _
                  pFindTxt, pReplaceTxt
            End If
          Next
        End If
      Case Else
        'Do Nothing
      End Select
      On Error GoTo 0
      'Get next linked story (if any)
      Set rngStory = rngStory.NextStoryRange
    Loop Until rngStory Is Nothing
  Next
End Sub
Public Sub SearchAndReplaceInStory(ByVal rngStory As Word.Range, _
    ByVal strSearch As String, ByVal strReplace As String)
  With rngStory.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = strSearch
    .Replacement.Text = strReplace
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll
  End With

End Sub


Private Sub UserForm_Click()

End Sub
Avatar billede doktoren001 Juniormester
09. maj 2011 - 11:12 #1
lukkes
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester