Solved

VB + Excel + File upload

Posted on 2002-04-22
13
422 Views
Last Modified: 2008-02-01
Hello,

Here's my situation.
I have a Excel file with a ODBC connection to a SQL Server. We open that file and refresh it everyday then upload it to our FTP server for archive.

We would like to create a VB application that will automate this tasks. Preferably in this order.

Run VB app.

Open excel file and refresh the ODBC connection
Save excel file
Close excel file
Open FTP connection to ftp.somewhere.org
Upload saved Excel file.
Close FTP connection

Close VB app.

Thanks,

jetx
0
Comment
Question by:jetx
  • 6
  • 6
13 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 6961001
Hi jetx,

Got exactly something like this running, only with ADO to an Access DB

-it runs excel to update data from the web through http
-puts results into an Access DB
-runs some other Excel comps for update DB and charting
-uploads charts to ftp server

can try to make a skimmed down version for you to play with
:O)Bruintje
0
 
LVL 4

Author Comment

by:jetx
ID: 6961046
Hi Bruintje,

Thanks for the comment.

I was told that this is what I need to do for the excel to refresh using VBA.

The object you need to refresh is called "QueryTable", the object name is "vk_Shipments", and the function to be called on this object is "Refresh".

Though, I don't know how to use that to my advantange in VB.

Hmmm.. Maybe I should do all my coding in VBA, if that is the case, It would sure help having a FTP code to upload the data to the FTP server.

jetx
0
 
LVL 4

Author Comment

by:jetx
ID: 6961047
Hi Bruintje,

Thanks for the comment.

I was told that this is what I need to do for the excel to refresh using VBA.

The object you need to refresh is called "QueryTable", the object name is "vk_Shipments", and the function to be called on this object is "Refresh".

Though, I don't know how to use that to my advantange in VB.

Hmmm.. Maybe I should do all my coding in VBA, if that is the case, It would sure help having a FTP code to upload the data to the FTP server.

jetx
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6961071
Hi Jetx,

it would make things a lot easier to upload directly from Excel since you can do it all in one environment and saves you the issues of closing and opening since you could leave that to a scheduler where the job runs

i'll post a simple setup for Excel FTP

Better yet a module and a link to the FTP component(Free) i use

:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6961089
here's the ftp code for a module in Excel

----------------------------------------
'basic ftp module using aspftp.dll
----------------------------------------
Option Explicit

Public Sub FTPInit()
   
    'create reference to ftp object
    Set m_objFTP = CreateObject("NIBLACK.ASPFTP")

End Sub

Public Sub FTPDeinit()
   
    'destroy reference to ftp object
    Set m_objFTP = Nothing

End Sub

Public Sub UploadFiles()
    Dim strmsg As String
    Dim strHomeDir As String
    Dim strRemoteDir As String
    Dim strFileNames$
   
    strHomeDir = ""
    strFileNames$ = ""
    strRemoteDir = ""
    strFileNames$ = ""
   
    Call FTPFile(strHomeDir & strFileNames$, strRemoteDir & strFileNames$)
   
End Sub

Public Sub FTPFile(ByVal strHome As String, _
                strRemote As String)
    Dim strmsg As String
    'connection worked...now get the file
    If m_objFTP.bQPutFile("ftp.test.org", "login", "password", strHome, strRemote, 2) Then
        'put was successful
        strmsg = "Put Successful!"
    Else
        'put failed...let user know
        strmsg = "Put Failed: " & m_objFTP.sError
    End If
End Sub
----------------------------------------

the component is called aspftp.dll can be downloaded here

http://www.15seconds.com/issue/981203.htm

you get the complete source + dll, so only have to register it on the machine and reference in your excel project and presto you got complete ftp functionality in Excel

i use that component now for 4 months with no trouble

:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6961096
on how to set this up

-register the ftp component on the machine

-first let the excel run some auto-open code
--run your query update on succes then
--save a copy of the file to upload in a local dir
--call ftpinit
--fill the params for uploading
--catch msg on success or failure
--call ftpdeinit
-remove the uploaded file from the local dir

-set this excel sheet on a scheduler and let it run

if you got any questions just leave a comment here
HTH:O)Bruintje
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6961157
learing...
0
 
LVL 4

Author Comment

by:jetx
ID: 6962844
Hi bruintje,

Thanks for your comments.

I was wondering if Excel will automatically run it's macro contents if I set it up using Windows Scheduler?

jetx
0
 
LVL 4

Author Comment

by:jetx
ID: 6962948
Hi bruintje,

Thanks for your comments.

I was wondering if Excel will automatically run it's macro contents if I set it up using Windows Scheduler?

jetx
0
 
LVL 44

Accepted Solution

by:
bruintje earned 400 total points
ID: 6963211
Hi jetx,

you can start an excel workbook like

path+workbookname + <macroname>

->

c:\temp\xl_comp.xls "yourmacro"

from the commandline or the scheduler which is the same procedure

:O)Bruintje
0
 
LVL 4

Author Comment

by:jetx
ID: 6966621
Thanks for your help bruintje.

jetx
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6966638
Glad it helped thanks for the grade,

have you got your process already running?
0
 
LVL 4

Author Comment

by:jetx
ID: 6966706
It seems to be working. Although, Excel doesn't automatically close after the task is finished.

Is it possible to close excel after the macro has finish running?

Maybe a macro that will close excel after the refresh/upload is complete?

Thanks.

jetx
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now