Dim oappWD as Word.Application: User defined type not defined 
Author Message
 Dim oappWD as Word.Application: User defined type not defined

Hi,
I get the error message : User defined type not defined (I hope, that's the
correct translation to English) in "Dim oappWD As Word.Application" the
following code.
Any ideas?

Looking forward to your answer

Bernd

Option Explicit

Private Sub cmdWord_Click()

    Dim oappWD As Word.Application
    Dim Doc, Paragraph

    On Error Resume Next
    Set oappWD = GetObject(, "Word.Application")
    If Err Then
        oappWD = CreateObject("Word.Application")
        oappWD.Activate
        oappWD.Visible = True
      Else
        oappWD.Visible = True
       End If

    On Error GoTo 0
    If oappWD.Options.VirusProtection = False Then
        oappWD.Options.VirusProtection = True
    End If

    'new
    Set Doc = oappWD.Documents.Add()
    Set Paragraph = Doc.paragraphs.Add()
    Paragraph.Range.Text = "Hallo Welt!"
    Paragraph.Range.Bold = True
    Paragraph.Range.Borders.Shadow = True

    'save
    oappWD.ActiveDocument.SaveAs "Hallo_Welt.Doc"

    'save all
    For Each Doc In oappWD.Documents
        Doc.Save
    Next

    'finish
    oappWD.Quit
    Set oappWD = Nothing
    Set Doc = Nothing
    Set Paragraph = Nothing

End Sub



Fri, 11 Jul 2003 03:39:11 GMT  
 Dim oappWD as Word.Application: User defined type not defined
Unlike VBA, all your variables are of the varient type.  Change to
Dim oappWd
or
Dim oappWd  ' As Word.Application

I like the second because it makes the code clearer but the apostrophe is
essential.

Steve


Quote:
> Hi,
> I get the error message : User defined type not defined (I hope, that's
the
> correct translation to English) in "Dim oappWD As Word.Application" the
> following code.
> Any ideas?

> Looking forward to your answer

> Bernd

> Option Explicit

> Private Sub cmdWord_Click()

>     Dim oappWD As Word.Application
>     Dim Doc, Paragraph

>     On Error Resume Next
>     Set oappWD = GetObject(, "Word.Application")
>     If Err Then
>         oappWD = CreateObject("Word.Application")
>         oappWD.Activate
>         oappWD.Visible = True
>       Else
>         oappWD.Visible = True
>        End If

>     On Error GoTo 0
>     If oappWD.Options.VirusProtection = False Then
>         oappWD.Options.VirusProtection = True
>     End If

>     'new
>     Set Doc = oappWD.Documents.Add()
>     Set Paragraph = Doc.paragraphs.Add()
>     Paragraph.Range.Text = "Hallo Welt!"
>     Paragraph.Range.Bold = True
>     Paragraph.Range.Borders.Shadow = True

>     'save
>     oappWD.ActiveDocument.SaveAs "Hallo_Welt.Doc"

>     'save all
>     For Each Doc In oappWD.Documents
>         Doc.Save
>     Next

>     'finish
>     oappWD.Quit
>     Set oappWD = Nothing
>     Set Doc = Nothing
>     Set Paragraph = Nothing

> End Sub



Fri, 11 Jul 2003 04:05:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Dim oappWD as Word.Application: User defined type not defined

2. Help: user defined type not defined (Outlook.Application)

3. Help!!-NEWBIE - Application Wizard -(WROX BOOK) Error- User defined type not defined

4. Help!!-NEWBIE - Application Wizard -(WROX BOOK) Error- User defined type not defined

5. User Control - User-defined type not defined

6. User Defined Type Not Defined

7. Compile Error: User-defined type not defined

8. User-defined type not defined (Access 97)

9. Excel : User-defined type not define

10. Compile Error - User defined type not defined

11. User-defined type not defined (Access 2000)

12. User- Defined type not defined

 

 
Powered by phpBB® Forum Software