如何操作Access / VBA中的附件字段 [英] How to Manipulate Attachment Field in Access/VBA

查看:177
本文介绍了如何操作Access / VBA中的附件字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经决定做一个自动机,这将是一个全新的问题,互联网上任何人都不会问。


目前,我的工作流程看起来像这个:


将数据导入Access - >计算一切 - >退出访问,打开Excel - >刷新所有数据并使用Automaton outlook发送电子邮件(vba excel)


现在我想将其更改为:


导入数据到访问 - >计算一切然后打开附加在table1(在附件字段内)的excel文件,刷新所有数据(直接连接到Access本身)然后保存并关闭excel(保存更改到附件字段)

- >在表单上,​​选择要报告的组,访问打开的Excel并运行在Excel文件中准备好的宏(excel仍然不可见),调用outlook automaton

- >新的电子邮件出现,关闭excel文件。


如果你的家伙可以建议任何更好的方法,我会跟着光。现在,我想知道如何做出我想出的新想法:D $ />

sothat,操作附件字段的vba代码是什么?


如何在vba中打开excel附件,运行excel宏?

如何关闭excel附件并将其保存回任何修改附件字段? :D


编辑1:

我当前的代码:

I''ve decided to do an automaton, and it''ll be whole new question that never ask by anyone else in internet.

Currently, My working flows is looklike this:

Import data to Access --> calculate everything --> Exit Access, Open Excel --> refresh all data and use Automaton outlook to send email (vba excel)

now I want to change it into this:

Import data to access --> calculate everything then open excel file that attached in table1 (inside attachment field), refresh all data (that connected directly to Access itself already) then save and close excel (save change into attachment field)
--> on Form, choose group to report, access open excel and run macro that prepaired in Excel file (excel still invisible), calling outlook automaton
--> new email appear, close excel file.

if you guy could advice any better method, I''ll follow the light. Right now, I want to know how to do my new idea that just pop up in my mind :D

sothat, what vba code to manipulate attachment field ?

how to open excel attachment inside vba, run excel macro ?
how to close excel attachment and save it back with any modify into attachment field ? :D

Edit 1:
my current code:

展开 | 选择 | 换行 | 行号

推荐答案

我绝对不惜一切代价反对附件字段。
主页>主题> microsoft access / vba>问题>表容量>帖子#3 附件将非常快速地通过你的可用文件空间。


首先,我会重新考虑Excel中你需要哪些无法在Access中完成的内容?你提到做计算在Access中,这就引出了一个问题。


其次,你提到你已经在Excel文件中使用了一些自动化来处理Outlook - 为什么不改变你的工作流程呢? />
导入访问>计算>自动打开Excel实例使用文件并刷新>发送您的电子邮件>关闭Excel的实例。恕我直言,比在附件领域尝试任何东西要好得多。


这是MS的基础知识将文件和图形附加到记录在你的数据库中

1)数据库中的附件仍然需要在用户的电脑上安装Excel

2)当你打开文件,它在临时位置打开

3)任何更改都必须在Access中进行交互以确认更改。

4)我想你会遇到使用这种方法可以解决很多问题。我想到的是,如果Excel文件在打开时会损坏它,会发生什么。


恕我直言,你会更好地使用自动化Excel实例。


啊......但是您想要在独占状态下打开链接到Access表的Excel文件存在问题: https://bytes.com/topic/access/answe...-closing-accdb 您有共享拒绝模式...正如您所发现的那样,将其更改为:模式=共享拒绝无这应该可以让事情很好地结合在一起。


(我还想到了使用MS Query而不是链接表;但是,我会在前面讨论这个问题提到的相关主题)



>>如果你坚持附件字段,我们将从那里开始。
I absolutely advise against the attachment field at all costs.
home > topics > microsoft access / vba > questions > table capacity> Post#3 Attachments will eat thru your available file space very quickly.

First I would rethink what is it in Excel that you need that cannot be done in Access? You mention doing the "calculations" in Access so it begs the question.

Second, You mention that you are already using some automation in the Excel file to handle Outlook - why not change your work flow a tad:
Import to Access > Calculate > Automation to open instance of Excel Using the file and refresh > Send your email > close instance of Excel. IMHO much better than attempting anything in the attachment field.

This is the basics that MS as about Attaching files and graphics to the records in your database.
1) Attachments in the database will still require that Excel be installed on the user''s pc
2) When you open the file, it opens in a temporary location
3) Any changes have to have interaction back in Access to confirm the change.
4) I think you''ll run into a lot of issues down the road using this method. The one that comes to mind is what happens if something corrupts the Excel file while it is open.

IMHO, you''d be better of with Automating the Excel instance.

Ahh... but you have an issue with the Excel file wanting to open your linked to Access tables in exclusive state: https://bytes.com/topic/access/answe...-closing-accdb You have the mode as share deny... as you''ve discovered, change that to: "Mode=Share Deny None" which should allow things to play together nicely.

(I''ve another thought about using MS Query instead of the linked tables; however, I''ll leave that discussion in the afore mentioned related thread)


>> If you insist on the Attachment field we''ll go from there.


@ZMBD:谢谢,我已经将我的报告.xlsb附加到访问附件字段,只有1个文件所以我们不必担心容量。


你的路由器非常聪明
访问>计算>自动打开Excel实例使用文件并刷新>发送您的电子邮件>关闭Excel的实例。

我也在考虑这个问题,但事实上我很懒,所以我找到了拉齐尔这样做的方法。

我会解释我4小时前完成的工作流程。

我的前工作流程(不是前女友)我以前每天都这样做:

数据原始 - >导入访问,计算,准备结果,关闭访问 - >打开excel,刷新所有(连接),用我的模块发送电子邮件(这个模块有3个步骤,根据我的条件过滤所有内容,保存,打开并复制我选择Outlook的所有范围,甚至附件本身到电子邮件 - 自动机部分)。

好的,现在,我的懒惰等级提升到了新的水平。我问自己,为什么我们不能代码访问做任何事情?

那一刻,脑子里有两个选项像爆米花一样弹出来(我觉得想要吃一些)


(这部分对于2个选项是相同的)

将report.xlsb附加到1个具有附件字段的新表中为了确保在我打开访问权限时我是否拥有该报告,我永远不会失去它。
但问题出来了,如果我将其附加到访问中,最快的方法是什么,最少的代码要做到这一点?

我去硫化互联网,他们使用envinr()获取文件名的临时文件夹和浓缩器:D好,可以工作但会出现更多问题。

然后我发现DAO.recordset2类型可以用来加载/保存/删除附件字段。经过1小时的搜索,我得到了救生员。

我坚持使用它并写了一些代码来制作所有东西。



这部分,我的函数会将我的报告文件从附件字段保存到D:\中。如果该文件不存在。

接下来,它刷新全部(连接),然后保存工作簿,删除oldone,将我的文件加载回附件字段。

(这部分是不同的)

现在我有2个选项来编写自动化代码:

1 /重写所有内容以后用访问Outlook的绑定自动机(或者只是从excel报告文件中复制然后调整)

2 / make excel运行宏然后关闭excel文件,保留outlook新邮件可见。

当它出现时,我的懒人水平突然同时增加了2级。

结果,我使用


@ZMBD: thank you, I''ve done attaching my report .xlsb into access attachment field, only 1 file so we don''t have to worry about capacity.

your router''s very clever
Access > Calculate > Automation to open instance of Excel Using the file and refresh > Send your email > close instance of Excel.
I was thinking about this too, but the fact that I''m lazy, so I found the Lazier way to do this.

I''ll explain my working flow that I have done 4hours ago.

My Ex-workflow (not ex-girl friend) that I used to do everyday is like this:
Data raw --> import into access, calculate, prepair result, close access --> open excel, refresh all (connection), send email with my module (this module have 3 step, filter everything with my condition, save, open and copy all-ranges I choose to Outlook, even attachment itself to email - automaton part).

ok, now, my lazy level increase to new level. I ask my self, why don''t we code access to do everything ?
at that moment, there arre 2 options pop-up in my mind like popcorn (I feel like want to eat some)


(this part is the same for 2 options)
attach the report.xlsb into 1 new table that having attachment field, to make sure whether I have or not that report excel at the moment I open access, I will never lose it.
but the problem come out, if I attachment this into access, what is the fastest way, least code to do that ?
I go sulfing internet and they use envinr() to get the temp folder and concenater with file name :D well, could work but more problem will appear.
then I findout DAO.recordset2 type can be use to load/save/delete attachments field. after 1hours seaching, I tho I got my lifesaver.
I sticked to it and wrote somecode to craft everything together.


On this part, my function will save my report file from attachment field into "D:\" if that file does not exist.
next, it refresh all (connection), then save workbook, delete oldone, load my file back to attachment field.

(this part is the different)
Now I have 2 options to code automation outlook:

1/ rewrite everything with later binding automaton for outlook in access (or just copy from excel report file then tweak)

2/ make excel run macro inside it then close excel file, leave the outlook new email visible.

when it come to this, my lazy level suddenly increased 2 level at the same time.
As the result, I use


展开 | 选择 | Wrap | 行号



我以前每天做的前工作流程(不是前女友)是这样的:

数据原始 - >导入访问,计算,准备结果,关闭访问 - >打开excel,刷新所有(连接),用我的模块发送电子邮件(这个模块有3个步骤,根据我的条件过滤所有内容,保存,打开并复制我选择Outlook的所有范围,甚至将附件本身发送到电子邮件 -

自动机部分)。
My Ex-workflow (not ex-girl friend) that I used to do everyday is like this:
Data raw --> import into access, calculate, prepair result, close access --> open excel, refresh all (connection), send email with my module (this module have 3 step, filter everything with my condition, save, open and copy all-ranges I choose to Outlook, even attachment itself to email -
automaton part).



那么为什么不直接从访问中发送信息作为报告?带插件的Acc2010可以发送报告,格式化为PDF文件,Acc2013使用内置PDF生成器进行。

So why not send the information directly from access as a report? Acc2010 with addin can send the report, as formatted to a PDF file and Acc2013 does that with the built-in PDF generator.


这篇关于如何操作Access / VBA中的附件字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆