ms访问vba - 从excel读取,并更新excel [英] ms-access vba - read from excel and also update that excel
问题描述
创建一个简单的访问数据库,只有1个表单和1个按钮才能运行打开现有空Excel(含1个工作表)的代码,并在其第一个单元格中写入X。它做的工作,但工作簿是隐藏的,我必须手动取消隐藏它。也就是说,在执行VBA代码之后,我打开excel文件,它全部变灰了。我必须单击视图选项卡,然后选择取消隐藏选项,一切都很好,我可以看到,根据需要更新了单元格。如果我拿出在Excel文件中写入X的VBA行,它不会隐藏工作簿。如何解决工作簿被隐藏的问题?
Created a simple access DB with only 1 form and 1 one button to run code that opens an existing empty excel (with 1 worksheet) and writes "X" in its 1st cell. It does the job but the workbook is hidden and I have to manually unhide it. That is, after the VBA code is executed I open the excel file and it is all grayed out. I have to click the "view" tab and then select the "Unhide" option and all is fine and I can see that the cell was updated as needed. If I take out the VBA line that writes "X" in the excel file, it doesn't hide the workbook. How do I solve the problem of the workbook being hidden?
Windows 7和Office2013。
Windows 7 and Office2013.
谢谢! !!
这是代码:
Private Sub Command0_Click()
Dim my_xl_app As Object
Dim my_xl_worksheet As Object
Dim my_xl_workbook As Object
Set my_xl_app = CreateObject("Excel.Application")
my_xl_app.UserControl = True
my_xl_app.Visible = False ' yes. I know it's the default
Set my_xl_workbook = GetObject("D:\Dropbox\MASAV\HIYUVIM\AAA.xlsx")
Set my_xl_worksheet = my_xl_workbook.Worksheets(1)
my_xl_worksheet.Cells(1, "A") = "V"
my_xl_workbook.Close SaveChanges:=True
Set my_xl_app = Nothing
Set my_xl_workbook = Nothing
Set my_xl_worksheet = Nothing
End Sub
推荐答案
S olved! !!
这是没有隐藏我的整个工作簿的代码:
Here is the code that works without hiding my entire workbook :
Private Sub Command0_Click()
Dim my_xl_app As Object
Dim my_xl_worksheet As Object
Dim my_xl_workbook As Object
Set my_xl_app = CreateObject("Excel.Application")
Set my_xl_workbook = my_xl_app.Workbooks.Open("D:\Dropbox\MASAV\HIYUVIM\AAA.xlsx")
Set my_xl_worksheet = my_xl_workbook.Worksheets(1)
my_xl_workbook.Sheets(1).Range("A1").Value = "V"
my_xl_workbook.Close SaveChanges:=True
Set my_xl_app = Nothing
End Sub
在这个论坛中得到答案,在另一个逃脱我的眼睛的线程...
Got the answer right here in this this forum, in another thread which escaped my eyes...
非常感谢这个美妙的论坛!!!!
这篇关于ms访问vba - 从excel读取,并更新excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!