HTTP Posting Document

T

turp1twin

I am new to VBA and Word macros in general and have a question. Is it
possible to HTTP Post the ActiveDocument to a URL after it has been closed or
saved? Perhaps in the autoClose method? Since I am new to Word automation I
am having a hard time finding the answer from the Document object docs. I
have found examples of how to POST arbitrary data from the Document, but not
the entire binary Document itself. Any help would be appreciated. Cheers!
 
M

moi

I experimented a little with this (instead of HTTP post, I use FTP), but
when I try to send an ActiveDocument to my webspace, just nothing happens. I
can only get it to work when sending another file which is not open. So yes,
if you create a DocumentClose-event which opens another doc with the macro
and FTP the saved file from there, it should work.

Here's my code.



Option Explicit

Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet
As Long) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias
"InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As
String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal
sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal
lContext As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal
sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As
Long
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA"
(ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal
lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long)
As Boolean

Private Sub FTPUploadDocument()
Dim hConn As Long, hAndle As Long
Dim ftpSrv, ftpUsr, ftpPwd As String
ftpSrv = "ftp.server.here"
ftpUsr = "ur_id"
ftpPwd = "ur_pass"
hAndle = InternetOpen("WinWord FTP Demo", 0, vbNullString, vbNullString,
0)
hConn = InternetConnect(hAndle, ftpSrv, 21, ftpUsr, ftpPwd, 1, IIf(True,
&H8000000, 0), 0)
FtpPutFile hConn, "file.doc", "uploaded.doc", &H1, 0
InternetCloseHandle hConn
InternetCloseHandle hAndle
End Sub
 
T

turp1twin

Thanks for your response. I was hoping to avoid having to go the file system.
I guess if that is my only option I will have to try it. Thanks again for
your help. Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top