この問題は、現在多くの時間を費やしています。毎回アクセスを開始するコードを実行するたびに、ファイルの場所を読み込んだ後、そのファイルの場所をExcelで開き、変更して閉じます。私はこれが孤児を残していることが分かります。私は、インターネット上で提案されているすべての方法と可能な解決方法を試しましたが、何も助けてくれません。私のコードは以下の通りです。すべてのヘルプや提案は素晴らしいことだ:Excelデーモンインスタンス:Access VBA
Public Sub productdetailprinter()
Dim i As Double
Dim dbs As DAO.Database
Dim recSet As Recordset
Dim wb As Workbook
Dim ws As Worksheet
Dim tableName As String
Dim recTable As Recordset
Dim fld As DAO.Field
Dim k As Integer
Dim r As Integer
Dim intformat As Integer
Dim wrksht As Worksheet
Dim wrkbk As Workbook
Dim filelocation As String
Dim xl As Excel.Application
Set xl = CreateObject("Excel.Application")
xl.Visible = True
Set dbs = CurrentDb
Set recSet = dbs.OpenRecordset("tbl_formList")
Set wrkbk = xl.Workbooks.Open("<location>")
Set wrksht = wrkbk.Worksheets("databaselinks")
filelocation = wrksht.Range("C5").Value
wrkbk.Close
xl.Quit
Set wrksht = Nothing
Set wrkbk = Nothing
Set xl = Nothing
Set xl = CreateObject("Excel.Application")
xl.Visible = True
xl.Workbooks.Application.DisplayAlerts = False
xl.Workbooks.Application.AskToUpdateLinks = False
Set wb = xl.Workbooks.Open(filelocation & "\product_detail.xlsx")
Set ws = wb.Worksheets("details")
xl.Workbooks.Application.AskToUpdateLinks = True
xl.Workbooks.Application.DisplayAlerts = True
ws.Range("B3", Range("B3").End(xlDown)).Select
xl.Selection.Clear
ws.Range("C3", Range("C3").End(xlDown)).Select
xl.Selection.Clear
ws.Range("D3", Range("D3").End(xlDown)).Select
xl.Selection.Clear
i = ws.Columns("B").End(xlDown).Row
i = i + 1
Do Until recSet.EOF
'code lines
recSet.MoveNext
Loop
ws.Save
wb.Close
xl.Quit
Set xl = Nothing
Set ws = Nothing
Set wb = Nothing
recTable.Close
recSet.Close
End Sub
[インデント](https://en.wikipedia.org/wiki/Indent_style)は多くの利点を持っており、プロのプログラマにとって第二の天性でなければなりませんありがとうございました。 – MikeC
Excelを終了して別のインスタンスを作成する必要はありません。あなたはそれを使い続けることができます。通常、wsとwbを何も設定しないとxlを破棄します。 Excelのインスタンスが表示されているので、終了時を知ることができます。 – MikeC