dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Using CreateObject

  1. #1
    Join Date
    Jun 2002
    Location
    Lyman ME - USA | Oneonta NY - USA
    Posts
    399

    Using CreateObject

    Hi,
    I'm working with createobject to start a word application but i am checking to see if it exists when it's open...if it is open, i want the program to add a new document to it and make it active...

    now i know to use documents.add
    that isn't a problem, the problem comes when the app is opened before the program is started, then the object hasn't been set and i can't use documents.add so i'm trying to set the object but failing each time

    any suggestions?

    thanks for the help

    - nc
    "In a world without walls and barriers, what need is there for windows and gates!" - a mac ad
    "What was the best thing before sliced bread and when did sliced bread go out of existence?" - me
    "Software is like sex, it's better when it's free." - Linus Torvalds <- gotten from Andreas Masur


    Live Penguine! - Tux the linux mascot
    Vivez le penguine!, íViva en penguine!, Lang lebe der Pinguin!, Viva no penguine!, Viva sul penguine!

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    If you find it exists

    ..then use GetObject instead of CreateObject
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090
    The following code should help.
    'Add reference to Microsoft Word Object Library.
    Code:
    Private Sub Command1_Click()
       Dim wrd As Word.Application, doc As Word.Document
       On Error Resume Next
       Set wrd = GetObject(, "Word.Application")
       If Err <> 0 Then
          Set wrd = CreateObject("Word.Application")
          Err.Clear
       End If
       If Not wrd Is Nothing Then
          Set doc = wrd.Documents.Add
          doc.SaveAs "Mydoc"
          Debug.Print doc.Name, doc.ActiveWindow
          wrd.Quit
       End If
       Set wrd = Nothing
    End Sub

  4. #4
    Join Date
    Jun 2002
    Location
    Lyman ME - USA | Oneonta NY - USA
    Posts
    399
    didn't know how to cimperiali


    but thanks to both for the replies

    - nc
    Last edited by booogt; July 18th, 2002 at 12:44 PM.
    "In a world without walls and barriers, what need is there for windows and gates!" - a mac ad
    "What was the best thing before sliced bread and when did sliced bread go out of existence?" - me
    "Software is like sex, it's better when it's free." - Linus Torvalds <- gotten from Andreas Masur


    Live Penguine! - Tux the linux mascot
    Vivez le penguine!, íViva en penguine!, Lang lebe der Pinguin!, Viva no penguine!, Viva sul penguine!

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)