Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2003, 12:04 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Destroying Excel an Word Objects

Hello,

I've got a problem to destroy word and excel objects generated via VBA: I would like to destroy these objects after I saved the result (some kind of queries from the database being written to a word document ...), but I don't have a clue how to do this.

Here are abstracts of the code I use:

1) The word problem:

...

On Error Resume Next

    Set wapp = GetObject(, "Word.Application")

On Error GoTo 0


    If wapp Is Nothing Then
        Set wapp = CreateObject("Word.Application")
    End If


    'open document
    wapp.Documents.Add

    'show document
    With wapp
        .Application.Visible = True
        .Application.Activate
    End With

    wapp.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

    With wapp.Selection.Font
        .name = "Arial Narrow"
        .Size = 11
        .Bold = False
    End With

    With wapp.Selection
        .ParagraphFormat.Alignment = wdAlignParagraphCenter
        .TypeText ("text")
        .InsertDateTime DateTimeFormat:="dd.MM.yyyy HH:mm", InsertAsField _
            :=False, DateLanguage:=wdGerman, CalendarType:=wdCalendarWestern, _
            InsertAsFullWidth:=False
        .TypeText (")")
        If .HeaderFooter.IsHeader = True Then
            wapp.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
        Else
            wapp.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
        End If

        .ParagraphFormat.Alignment = wdAlignParagraphCenter
        'Format Text
        With .Font
            .name = "Arial Narrow"
            .Size = 11
            .Bold = False
        End With

        .TypeText "As private and confidential"

    End With

    'Main document
    wapp.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

    With wapp.Selection
            .Style = ActiveDocument.Styles("Überschrift 1")
            .TypeText Text:="text"
            .TypeParagraph
        End With

    Dim str_name_doc As String
    str_name_doc = Now
    str_name_doc = Replace(str_name_doc, ":", "-")
    wapp.ActiveDocument.SaveAs Application.CurrentProject.Path & "\Ergebnisse\Aktueller Stand Eingabe " & str_name_doc & ".doc"
    'wapp.ActiveDocument.Close


The problem is, that if use that code for more than one time, and shutdown the word document before I use the code again, Access tells me, that there is no remote-server-host (Error 462).
Has anybody ever had this problem before or can tell me where I am doing wrong?

My second problem is how to destroy Excel objects. Here's the code I am using:

...

Private xlApp As Excel.Application
Private xlBook As Excel.Workbook
Private xlSheet As Excel.Worksheet

Private Sub Class_Initialize()

[...]

    On Error GoTo ERR_create_excel_object

        Set xlApp = GetObject(, "Excel.Application")
        Set xlBook = Excel.Workbooks.Open(Application.CurrentProject.Pa th & "\vorlage.xls")

    Exit Sub

ERR_create_excel_object:

        Set xlApp = CreateObject("Excel.Application")
        Set xlBook = Excel.Workbooks.Open(Application.CurrentProject.Pa th & "\vorlage.xls")

End Sub

And the destructor ...

Private Sub Class_Terminate()

    xlBook.Close
    xlApp.Quit


End Sub

Thank you very much in advance and sorry for my bad English!

Henning
 
Old November 10th, 2003, 12:54 PM
Authorized User
 
Join Date: Sep 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you tried, "set wapp = nothing"? same goes with excel objects???

Sam Gharnagh
Jr. Programmer Analyst at MOH
Comp Sci at UofW
 
Old November 12th, 2003, 08:06 PM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Have you tried:

   Set wapp = nothing

:)


--- Tom
 
Old November 12th, 2003, 08:07 PM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Also:

   Set xlApp = nothing


--- Tom





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to finding the Graphic objects in word doc madhan_needs_help Word VBA 2 August 8th, 2007 10:38 AM
Dynamically add objects based on Word Bookmarks a4d2a0m VB How-To 2 February 27th, 2007 03:57 AM
Wipe off the Picture objects from Excel Sheet Amjad.Mahmoood Excel VBA 4 September 11th, 2006 03:39 AM
Clearing Drawing Objects from a given Excel range Amjad.Mahmoood Pro VB 6 3 September 11th, 2006 01:06 AM
Loading and Destroying web user controls into a pa see07 ASP.NET 1.x and 2.0 Application Design 5 February 4th, 2005 04:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.