從MSAccess,我創建並填充XLS工作表。所有工作都按預期工作。作爲最後一步,我想清理XLS以用「」替換「0」值。從XLS宏MSAccess中的Excel自動化 - 使用VBA替換Chars?
造型,我嘗試以下,但MSACCESS VBA產生所需的對象錯誤消息:
Dim appXLS As Object
Dim wbk As Object
Dim wks1 As Object
Dim wks2 As Object
Dim wks3 As Object
Dim wks4 As Object
Set appXLS = CreateObject("Excel.Application")
Set wbk = appXLS.Workbooks.Add(1)
appXLS.Visible = True
wbk.Activate
Set wks4 = wbk.Sheets.Add(After:=wbk.Sheets(wbk.Sheets.COUNT))
wbk.Sheets(4).NAME = "Item Detail"
Set wks4 = wbk.ActiveSheet
'>>populate and format the XLS from MSAccess VBA
'... it's working as required
'Clean-Up:
wks4.Range("P:P").Select
Selection.Replace What:="0", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
任何建議,以糾正MSACCESS VBA這種做法?
我不會添加一個答案,因爲每個人都在說我是什麼要說,但 - 我認爲'表(4)'是您創建爲'wks4'的表單?你可以使用'wks4.Name =「Item Detail」'並且當你創建表單時移除Set wks4 = wbk.ActiveSheet'。您可能還需要添加一些代碼來檢查「商品明細」是否已經存在。 –