问题描述
我正在创建一个表单,根据用户选择的模型类型,法兰类型和一系列行大小来选择数据。这不是问题,我能够从表格中获得正确的报告。
我的问题是我用来将报告导出到Excel的按钮。我希望按钮使用基于表单中选择的参数的文件名保存文件,然后打开excel文件,删除空列,稍稍移动表(只是使边框可见),然后添加行到让它看起来像一张漂亮的桌子。当我点击按钮时,我大部分时间都在工作。当excel已经打开时,它似乎无法正常工作,特别是如果有一个已经打开的excel文件是由此按钮创建的。真正让我感到的是它会给出一个对象''_Global''的方法范围。有时会出错,但是如果我关闭excel文件再试一次就没问题了。
请记住,对于Access和VBA来说,我是一个完整的新手 - 一切你看到我在上周教过自己了。所以随意像对待孩子一样对待我,我正在学习每一步。
我省略了表格上有关选项列表的所有代码。这只是按钮。
I am creating a form that selects data based on a user selected model type, flange type, and a range of line sizes. This hasn''t been a problem, I am able to get the correct report from the form thus far.
My issue is the button I am using to export the report to excel. I want the button to save the file with a filename based on the parameters selected in the form, then open the excel file, delete empty columns, move the table a bit (just so the borders are visible), and then add the lines to make it look like a nice table. I am at the point where this works most of the time when I click the button. It seems to be not working properly whenever excel is already open, especially if there is an excel file that is already open which was created by this button. What really gets me is that it''ll give a "Method ''Range'' of object ''_Global'' " error sometimes but if I close the excel file and try again it will work no problem.
Keep in mind that I am a complete novice when it comes to Access and VBA in general - everything you see here I have taught myself in the last week. So feel free to treat me like a child, I am learning each step of the way.
I have omitted all the code concerning the option lists on the form. This is just the button.
推荐答案
这篇关于将报表导出到Excel并使用Access VBA格式化它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!