Being a non-traditional programmer, I tend to look at things in a different perspective. This happens to be one of those times. I have a accdb
that currently runs and outputs PDF
files every 2 minutes. The new PDF
's overwrite the old ones except when someone has one of the files open. In that case it skips the open file, the reattempts 2 minutes later. The issue I am running into is that some of the users who open these PDF
's, minimize them and forget about them, in some cases, not allowing the file to be updated for days, and even weeks. What I want to do is to embed a work action to close the file after several hours of being open. I found how to do so enter link description here I have tested it, and it works. The problem I have is the I need somehow via VBA
, embed that action into the PDF
when it is created. The code I use to create it is:
作为一个非传统的程序员,我倾向于以不同的视角看待事物。这恰好是其中一次。我有一个accdb,目前每2分钟运行并输出PDF文件。新的PDF会覆盖旧的PDF,除非有人打开其中一个文件。在这种情况下,它会跳过打开的文件,2分钟后重新尝试。我遇到的问题是打开这些PDF的一些用户,最小化它们并忘记它们,在某些情况下,不允许文件更新数天甚至数周。我想要做的是在打开几个小时后嵌入一个工作动作来关闭文件。我发现如何这样做输入链接描述在这里我测试了它,它的工作原理。我遇到的问题是我需要以某种方式通过VBA,在创建时将该动作嵌入到PDF中。我用来创建它的代码是:
DoCmd.OutputTo acOutputReport, "H&B Stock Research", acFormatPDF, strPathAndFile, False
All the sites I have researched show you how to accomplish adding the script/action though the Acrobat GUI. But I want to try to progmattically insert it via VBA
in Access. The reason for this is that this file gets produced every 2 minutes, and there are approximately 50 copies that are updated.
我研究过的所有网站都向您展示了如何通过Acrobat GUI完成添加脚本/操作。但我想尝试通过VBA在Access中进行前导。原因是该文件每2分钟生成一次,并且大约有50个副本被更新。
1 个解决方案
#1
0
I would keep the operational code in one place for better overview. Having said that, I would extend your current VBA function to check whether the file is open and if open for longer than 2 hours and a new version is available to copy. Close the opened file and copy the newest version.
我会将操作代码保存在一个位置以便更好地进行概述。话虽如此,我会扩展您当前的VBA功能,以检查文件是否已打开,如果打开时间超过2小时,则可以复制新版本。关闭打开的文件并复制最新版本。
This way you will have full control of copying the newest version and can manage your code all in one place.
这样您就可以完全控制复制最新版本,并可以在一个地方管理您的代码。
I assume you already have the function to check whether the PDF is open. adding this code will help you to terminate the opened file.
我假设你已经有了检查PDF是否打开的功能。添加此代码将帮助您终止打开的文件。
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
'Constants that are used by the API
Const WM_CLOSE = &H10
Dim mHwnd As Long
mHwnd = FindWindow(vbNullString, mFileName & " - Adobe Reader") ' application title
If IsWindow(mHwnd ) = 1 Then ' or just If mHwnd Then
'Send termination signal
' you can also capture the return value from postmessage to understand errors.
PostMessage mHwnd , WM_CLOSE, 0&, 0& '
Debug.print "File was open but closed: " & mFileName
End If
.. continue with your copy function
see this: https://support.microsoft.com/en-us/kb/176391
请参阅:https://support.microsoft.com/en-us/kb/176391
#1
0
I would keep the operational code in one place for better overview. Having said that, I would extend your current VBA function to check whether the file is open and if open for longer than 2 hours and a new version is available to copy. Close the opened file and copy the newest version.
我会将操作代码保存在一个位置以便更好地进行概述。话虽如此,我会扩展您当前的VBA功能,以检查文件是否已打开,如果打开时间超过2小时,则可以复制新版本。关闭打开的文件并复制最新版本。
This way you will have full control of copying the newest version and can manage your code all in one place.
这样您就可以完全控制复制最新版本,并可以在一个地方管理您的代码。
I assume you already have the function to check whether the PDF is open. adding this code will help you to terminate the opened file.
我假设你已经有了检查PDF是否打开的功能。添加此代码将帮助您终止打开的文件。
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
'Constants that are used by the API
Const WM_CLOSE = &H10
Dim mHwnd As Long
mHwnd = FindWindow(vbNullString, mFileName & " - Adobe Reader") ' application title
If IsWindow(mHwnd ) = 1 Then ' or just If mHwnd Then
'Send termination signal
' you can also capture the return value from postmessage to understand errors.
PostMessage mHwnd , WM_CLOSE, 0&, 0& '
Debug.print "File was open but closed: " & mFileName
End If
.. continue with your copy function
see this: https://support.microsoft.com/en-us/kb/176391
请参阅:https://support.microsoft.com/en-us/kb/176391