Results 1 to 7 of 7
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Task command (VB6.0)

    When I use the following code below in Word - VBA - it runs smootly.

    However when I add the below code into a VB project and compile I get an error on "Task". i get a compile error 'user defined type not defined"


    'determines if application/taks is running
    Public Function bIsAppRunning(ByVal vsAppName As String) As Boolean
    Dim aTask As Task
    bIsAppRunning = False

    For Each aTask In Tasks
    If aTask.Name = vsAppName Then
    bIsAppRunning = True
    Exit Function
    End If
    Next aTask
    End Function

    any ideas?
    many thanks
    diana

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Task command (VB6.0)

    Task and Tasks are part of the Word object model, so you't need to create a Word.Application object.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task command (VB6.0)

    Hi Hans

    Heres my code: Ive defined this line and now i when I compile the error displays "User defined type not defined"
    Public objWordApp As Word.Application




    'set application objetcs
    Public objWordApp As Word.Application


    'dd
    Sub Main()

    Dim objApp As Object
    Dim RetVal


    'check if DM application is running
    If bIsAppRunning("PowerDOCS Main Window") Then
    Else

    'if DM is not running then fire up the DM application
    RetVal = Shell("explorer.exe /e,/root,::{4577EA30-A1DF-11D0-BA3E-00A024746296}", 1)

    'there maybe a delay as DM and the scripts fire up therefore wait
    Call Wait

    End If


    End Sub

    'determines if application/taks is running
    Public Function bIsAppRunning(ByVal vsAppName As String) As Boolean
    Dim aTask As Task
    bIsAppRunning = False

    For Each aTask In Tasks
    If objWordApp.aTask.Name = vsAppName Then
    bIsAppRunning = True
    Exit Function
    End If
    Next objWordApp.aTask


    End Function

    Public Function Wait()

    NewHour = Hour(Now())
    NewMinute = Minute(Now())
    NewSecond = Second(Now() + 20) 'Incorporate a 20-second delay
    WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)
    Application.Wait WaitTime

    End Function

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Task command (VB6.0)

    > Public objWordApp As Word.Application

    To use compile-time binding, your environment must have a reference to the Word object library. If that is not possible or not desirable, use run-time ("late") binding:

    Public objWordApp As Object
    ...
    Set objWordApp = CreateObject("Word.Application")

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task command (VB6.0)

    Thank you Jefferson

    Now when I compile I get an error on line

    Dim aTask As Task


    ..."User defined type not defined"


    diana [img]/forums/images/smilies/ohmy.gif[/img])

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Task command (VB6.0)

    The answer is the same: you must either set a reference to the Microsoft Word n.0 Object Library in Project | References..., or declare aTask as an Object instead of as a Task. And your loop will have to be different:

    For Each aTask In objWordApp.Tasks
    If aTask.Name = vsAppName Then
    bIsAppRunning = True
    Exit Function
    End If
    Next aTask

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task command (VB6.0)

    thank you Hans

    that worked

    diana :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •