Link to home
Start Free TrialLog in
Avatar of jetx
jetxFlag for Canada

asked on

VB + Excel + File upload

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
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

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
Avatar of jetx

ASKER

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
Avatar of jetx

ASKER

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
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
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
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
Avatar of Richie_Simonetti
learing...
Avatar of jetx

ASKER

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
Avatar of jetx

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jetx

ASKER

Thanks for your help bruintje.

jetx
Glad it helped thanks for the grade,

have you got your process already running?
Avatar of jetx

ASKER

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