• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

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
0
jetx
Asked:
jetx
  • 6
  • 6
1 Solution
 
bruintjeCommented:
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
 
jetxAuthor Commented:
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
 
jetxAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
bruintjeCommented:
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
 
bruintjeCommented:
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
 
bruintjeCommented:
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
 
Richie_SimonettiIT OperationsCommented:
learing...
0
 
jetxAuthor Commented:
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
 
jetxAuthor Commented:
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
 
bruintjeCommented:
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
 
jetxAuthor Commented:
Thanks for your help bruintje.

jetx
0
 
bruintjeCommented:
Glad it helped thanks for the grade,

have you got your process already running?
0
 
jetxAuthor Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now