Solved

VB + Excel + File upload

Posted on 2002-04-22
13
424 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

17 Experts available now in Live!

Get 1:1 Help Now