Solved

Transfer files to Excel

Posted on 2004-04-23
14
3,141 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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