Solved

Transfer files to Excel

Posted on 2004-04-23
14
3,170 Views
Last Modified: 2012-08-14
To my opinion this question doesn't  belong here but I will try any way, because it's Client Access related. Putting it in the Excel area will probably give the reaction "Client what??"
so......
Every month one of our users asks me to help to download a file from the as/400 in excel.
(i'ts done with the excel CA addin "Transfer from as/400").
I already have saved the transfer file "GetMyFile.DFT" but he is stil not able to do it.

I like to creat a Sheet that will automatically starts the transfer...... How to do?????

Regards....
0
Comment
Question by:theo kouwenhoven
[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
  • 5
  • 5
  • 2
  • +2
14 Comments
 
LVL 14

Expert Comment

by:daveslater
ID: 10898699
Hi

open excel press alt F11 to get VB code

select this workbook



vb code
Private Sub Workbook_Open()

    a1 = Shell("C:\PROGRA~1\IBM\CLIENT~1\cwbtf.exe U:downnload.dtf")
    Call ChkApp(a1)
    Workbooks.Open Filename:="U:downladedworkbook.xls"

end sub


'' check if an applciation is still open
Sub ChkApp(Apid)

Dim t1 As Double
Dim t2 As Double

On Error GoTo NoApp


Do



    Do Until t2 > Timer
        t2 = Timer + 2
    Loop
   
    Do Until Timer > t2
        DoEvents
    Loop
       
    AppActivate Apid, False
   
Loop

Resume1:
Exit Sub

NoApp:

Resume Resume1


End Sub


dave
0
 
LVL 2

Expert Comment

by:csimonds
ID: 10898748
You could create a data transfer shortcut for the user that creates an Excel file and runs automatically when he/she opens it. The kicker is that the target filename would always be the same. Maybe a big deal, maybe not.

Create a new transfer.
Open Properties and click on the Startup tab.
  Select 'Run transfer request automatically'
  Click 'OK'
Select 'File' for the Output device.
Click the Details button and pick one of the BIFFx(Excel) file types. (you might have to experiment a bit. BIFF8 worked for me and Excel97)
Fill in the other stuff and save it.
Put a shortcut on the user's desktop.


I thought a fella could create an automatic macro in Excel but, at least in Excel97, the CA add-in doesn't get recorded when I try recording a macro. Maybe it works in other versions.

--cs
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 10900710
Hi Dave,

I was already busy to do it with the cwbtf, but using the excel add-un sould be preferabel. I will wait for an other solution, otherwise I will copy and paste this moanday morning.

Thanks (again).

0
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
LVL 27

Expert Comment

by:tliotta
ID: 10905376
murphey2:

I work very little on the Excel side, so I have to ask questions...

What does your user do with the file? Is it simply loaded or is it updated and uploaded back to your AS/400? If it's simply loaded, does it matter what form it's in? That is, could you create a .CSV file for the user or even a .HTML file? Excel can handle either and both could be generated on your AS/400 and stored in a directory for the user. Then it'd be a simple drag/drop or double-click from a mapped drive or even a desktop shortcut.

Tom
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 10907009
Tom

Thanks for the response, I can also create an XLS file on the as/400 and write it to maped drive, but the users are not alowed to use maped as/400 driver (company policy).
So I have to download it with cwbtf or the excel build in function, Normally the build in function is used, but some users seems even to be to stupid to remember something or read a very simple work-instuction. :-)

Thanks

0
 
LVL 6

Expert Comment

by:dedy_djajapermana
ID: 10927894
hi murphey,

i don't have access to cwbtf and as/400 right now, but i think you can do it this way:
create a macro named auto_exec it will be automatically opened when the workbook is opened.
i'm not very good in the VB macro too, but i think you can use "record macro" method, just record the steps to open the .dft file, and save it as auto_exec macro.
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 10929516
Hi Dave,

Your sugestion works (partialy), but when the system is slow (what happens frequently) the the macro try to load the file before it is downloaded.

0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 10929517
Hi Dave,

Your sugestion works (partialy), but when the system is slow (what happens frequently) the the macro try to load the file before it is downloaded.

0
 
LVL 14

Expert Comment

by:daveslater
ID: 10929703
Hi
is it running on NT/2k/XP or 95/98/me

0
 
LVL 14

Expert Comment

by:daveslater
ID: 10929763
Have you checked theauto run / close on completionj under properties / startup?

The checkapp should wait till the transfer closes before returning control back to the open statement.

Dave
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 10930160
Hi Dave,

It's running on W2K and both checkboxes are checked.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 10934010
murphey2:

Note that via the /QNTC file system, it isn't necessary for the user to map a drive -- the AS/400 could write directly to a directory on the user's PC. If it's Win2K, it _might_ be easy if the user id/passwords match.

If they don't match, it's possible for the AS/400 job to do a profile switch to do the transfer under a profile that does match.

Tom
0
 
LVL 14

Accepted Solution

by:
daveslater earned 50 total points
ID: 10937762
Hi Murphey
I have ran it a few times here and it works file (29000) records in about 20 seconds.
the only other thing I do in the .Dtf file is

Notify=0

Dave

0
 
LVL 14

Expert Comment

by:daveslater
ID: 13150601
Hi I have had a reques to comment the VB code so here it is.

Private Sub Workbook_Open()


'Note   By default, the Shell function runs other programs asynchronously. This means
'that a program started with Shell might not finish executing before the statements
'following the Shell function are executed.

'Set a1 to the windows shell process.
    a1 = Shell("C:\PROGRA~1\IBM\CLIENT~1\cwbtf.exe U:downnload.dtf")
    Call ChkApp(a1) '' loop until the download has finished
    Workbooks.Open Filename:="U:downladedworkbook.xls" 'open the donwloaded file
end sub


'' check if an applciation is still open
''Apid is a windows event number created by Shell - this is like an AS/400 job number

Public Sub ChkApp(Apid)
Dim t1 As Double
Dim t2 As Double

'' Global error capture - this exits the sub when the application is no longer running
On Error GoTo NoApp

'' Loop to infinity
Do
'' ensure t2 is > timer (23:59:59 + 2 seconds = 00:00:01)
    Do Until t2 > Timer
        t2 = Timer + 2
    Loop

    '' wait 2 seconds (release CPU to other windows tasks)
        Do Until Timer > t2
        DoEvents
    Loop

    '' activate the requested application, when it has finished
    ''an error will be isued, this will exit the infiity loop
    AppActivate Apid, False '' false = do not wait for the application - just check it is there
   
Loop

'' Exit the sub
Resume1:
Exit Sub

'' When the application has finished the error trapping will force the code here
NoApp:
Resume Resume1 '' I like to tidy up with a resume!

End Sub


Regards

dave
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
Let's recap what we learned from yesterday's Skyport Systems webinar.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

632 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