?
Solved

VB + Excel + File upload

Posted on 2002-04-22
13
Medium Priority
?
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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 1600 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 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