ms-access vba - 从 excel 读取并更新该 excel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20073155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ms-access vba - read from excel and also update that excel
提问by gadi
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?
创建了一个只有 1 个表单和 1 个单按钮的简单访问数据库,用于运行打开现有空 excel(带有 1 个工作表)并在其第一个单元格中写入“X”的代码。它可以完成工作,但工作簿被隐藏,我必须手动取消隐藏它。也就是说,在执行VBA代码后,我打开excel文件,它全都变灰了。我必须单击“查看”选项卡,然后选择“取消隐藏”选项,一切都很好,我可以看到单元格已根据需要更新。如果我取出在 excel 文件中写入“X”的 VBA 行,它不会隐藏工作簿。如何解决工作簿被隐藏的问题?
Windows 7 and Office2013.
Windows 7 和 Office2013。
Thank you!!!
谢谢!!!
Here is the code:
这是代码:
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
回答by gadi
S o l v e d !!!
解决了 !!!
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...
在这个论坛上得到了答案,在另一个逃过我眼睛的帖子中......
Thanks a lot to all in this wonderful forum!!!!
非常感谢这个精彩论坛中的所有人!!!!
回答by Mirek F.
Use this:
用这个:
Workbooks(1).Windows(1).Visible = True