This looks to be exactly what I am trying to do but I'm a complete novice with VBA.
When I run this macro I get the error "Error: file not found" so i put in a MsgBox here
'Check the local path and file to ensure
'that either the a file that exists was
'passed or a wildcard was passed.
If InStr(sLocalFile, "*") Then
If InStr(sLocalFile, " ") Then
FTPUpload = "Error: Wildcard uploads do not work if the path contains a " & _
"space." & vbCrLf
FTPUpload = FTPUpload & "This is a limitation of the Microsoft FTP client."
Exit Function
End If
ElseIf Len(sLocalFile) = 0 Or Not oFTPScriptFSO.FileExists(sLocalFile) Then
If Not oFTPScriptFSO.FileExists(sLocalFile) Then
MsgBox "No file system object found"
End If
'nothing to upload
FTPUpload = "Error: File Not Found."
Exit Function
End If
....and it turns out the oFTPScriptFSO.FileExists(sLocalFile) is not existing. What am I doing wrong?
tes wrote:
Thank you very, very much!!!
03-Nov-09
Thank you very, very much!!!
Previous Posts In This Thread:
Need help with FTP upload script (beginner)
I need help :-
In this article there is a script to upload a file via FTP in VBA
http://www.naterice.com/articles/5
What I want to do is run this script with a pushbutton or when th
file get's closed
I am new to VBA, and the part where they tell me to supply th
information is confusing
As I see it, I have to "open" the FTPupload and parse the informatio
about the server when I call for the script
But how do I do this
I have tried in Excel to past the code in the VBA-editor, but how ca
I get a button to open this function with the information it needs
I am very, very new to this, any help is welcome
Thanks
There is a lot to learn here!
There is a lot to learn here
First, the code posted in the web page is VBScript, not VBA. The tw
languages are very similar, and in fact you can use the posted cod
with only a couple of small changes, which I will mention later
Second, the posted code consists of two *functions*, FTPUpload an
FTPDownload. To make either of them work, you need to call it from
*subroutine* or Sub. The distinction is explained i
http://www.word.mvps.org/FAQs/MacrosVBA/ProcArguments.htm. To run cod
from a button, you need to assign the button to run the subroutine
and the subroutine then calls the function. (Buttons cannot ru
functions directly.) Se
http://www.word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm
All of this should go into a Word template -- not in a document -- an
that template should be stored in %appdata%\Microsoft\Word\STARTUP t
make the button and macro code available in all documents
If your purpose is only to upload the current document and never t
download documents, you can delete the FTPDownload function and no
worry about it
Here is a simple subroutine that can call FTPUpload to send the curren
document to the FTP server. You'll have to fill in the four constant
with the real values for your account on the server
'~~~~~~~~~
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long
Sub PutFTPFile(
Const Site = "ftpsite.com
Const userName = "myUserName
Const PW = "myPassword
Const Path = "subfolder
Dim rslt As Strin
Dim filenameToPut As Strin
If Len(ActiveDocument.Path) = 0 The
MsgBox "The document must be saved first.", vbCritical, "FTP
Exit Su
End I
filenameToPut = ActiveDocument.FullNam
rslt = FTPUpload(Site, userName, PW, filenameToPut, Path
MsgBox rsl
End Su
'~~~~~~~~~
Also, make these changes in the code from the web page
- In two places (one in each function), chang
Wscript.Sleep 100
t
Sleep 100
This will call the Sleep function in the Declare line (part o
Windows) instead of the Sleep function in the Wscript object fo
simplicity
- A few lines further down in each function, chang
FTPUpload = Tru
t
FTPUpload = "Done.
This will allow the result to be a little more meaningful when it i
displayed in the message box at the end of the subroutine.
- Declare the return type of the two functions "As String" like this:
Function FTPUpload(sSite, sUsername, sPassword, _
sLocalFile, sRemotePath) As String
and
Function FTPDownload(sSite, sUsername, sPassword, _
sLocalPath, sRemotePath, sRemoteFile) As String
Now you can assign a toolbar button to the PutFTPFile macro. Clicking
the button will upload the document (provided it has been saved at
least once). For production use, the macro should probably be modified
to check the value of ActiveDocument.Saved and refuse to upload if
that value is False.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
Thank you very, very much!!!
Thank you very, very much!!!
Cant get this to work
This looks to be exactly what I am trying to do but I'm a complete novice with VBA.
When I run this macro I get the error "Error: file not found" so i put in a MsgBox here
'Check the local path and file to ensure
'that either the a file that exists was
'passed or a wildcard was passed.
If InStr(sLocalFile, "*") Then
If InStr(sLocalFile, " ") Then
FTPUpload = "Error: Wildcard uploads do not work if the path contains a " & _
"space." & vbCrLf
FTPUpload = FTPUpload & "This is a limitation of the Microsoft FTP client."
Exit Function
End If
ElseIf Len(sLocalFile) = 0 Or Not oFTPScriptFSO.FileExists(sLocalFile) Then
If Not oFTPScriptFSO.FileExists(sLocalFile) Then
MsgBox "No file system object found"
End If
'nothing to upload
FTPUpload = "Error: File Not Found."
Exit Function
End If
....and it turns out the oFTPScriptFSO.FileExists(sLocalFile) is not existing. What am I doing wrong?
Submitted via EggHeadCafe - Software Developer Portal of Choice
Accessing IIS Hosted WCF Services from PHP
http://www.eggheadcafe.com/tutorial...ba-e3c3295d8277/accessing-iis-hosted-wcf.aspx