我想在Access中使用按钮创建一个表单"创建发票"。我尝试让它做到以下几点:
复制excel"发票模板";
移动excel"发票模板"来自文件夹" templates"到文件夹"发票";
打开"发票发送寄存器" (excel文件);
打开"客户地址注册" (excel文件);
将发票模板副本重命名为可以在文本框中输入的内容;
等一下;
打开新创建的Excel文件以在Excel中填写模板。
这是我提出的代码:
Private Sub Knop1_Click()
'Open register with customer adresses
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open "\\WDMyCloudEX4\Zakelijk\Documenten\Betalingen\Faktuur adressen.xlsx", True, False
Set xlApp = Nothing
'Open folder with invoices
Call Shell("explorer.exe" & " " & "\\WDMyCloudEX4\Zakelijk\Documenten\SFMT\Afleveringsbonnen 2008-heden\2017\Nieuwe systeem (1-3-2017)", vbNormalFocus)
'Make a copy of the invoice template
FileCopy "\\WDMyCloudEX4\Zakelijk\Documenten\SFMT\Afleveringsbon.xlsx", "\\WDMyCloudEX4\Zakelijk\Documenten\SFMT\Afleveringsbonnen 2008-heden\2017\Nieuwe systeem (1-3-2017)\Nieuwe afleveringsbon.xlsx"
'Define to what the invoice template should be renamed
Year = [Tekst3]
Month = [Tekst6]
Count = [Tekst9]
NEWNAME = Year + Month + Count
'Move and rename the invoice template copy
Name "\\WDMyCloudEX4\Zakelijk\Documenten\SFMT\Afleveringsbonnen 2008-heden\2017\Nieuwe systeem (1-3-2017)\Nieuwe afleveringsbon.xlsx" As "\\WDMyCloudEX4\Zakelijk\Documenten\SFMT\Afleveringsbonnen 2008-heden\2017\Nieuwe systeem (1-3-2017)\P95+$NEWNAME.xlsx"
'Wait a second to make sure the copiing is completed
Sleep (1000)
'Open the moved and renamed invoice template copy
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open "\\WDMyCloudEX4\Zakelijk\Documenten\SFMT\Afleveringsbonnen 2008-heden\2017\Nieuwe systeem (1-3-2017)\P95+telling", True, False
Set xlApp = Nothing
End Sub
任何帮助都会非常受欢迎,这让我发疯了......我已经尝试了好几个小时了。
答案 0 :(得分:0)
您尚未说明实际问题是什么,但我认为至少部分问题出在此代码中:
'Open register with customer adresses
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open "\\WDMyCloudEX4\Zakelijk\Documenten\Betalingen\Faktuur adressen.xlsx", True, False
Set xlApp = Nothing
在此代码中,您将创建一个Excel应用程序对象并通过该对象打开Excel工作簿,然后在打开工作簿后立即销毁该应用程序对象。所以你有效地打开然后立即关闭工作簿。