English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

For example, I have recorded a macro in an excel file and i need some data from a different saved file (i.e. txt or .xls). How do i use macros so that i could open that file and input the needed data from that file into the worksheet where i have recorded the macros?
And also, how would macros detect an error if the file chosen by the user is not the file intended for that purpose?

2006-10-02 18:21:08 · 2 answers · asked by Macross 2 in Science & Mathematics Engineering

Note: the chosen file is dependent upon the use. The file format is the same, but the name of the file may vary.

2006-10-02 18:51:36 · update #1

2 answers

You do the same thing you've already done, e.g., record the commands used to open a file and then copy the needed data into the existing worksheet.

Error checking requires you to write code to verify file names and types, as well as possibly verifying validity of the data within the file.

2006-10-02 18:46:34 · answer #1 · answered by arbiter007 6 · 0 0

You are asking for a big subroutine.
OK
openning excel files is by this line
Workbooks.open "C:\My documents\file1.xls"
then perform what you need
Text files can be opened using the old simple VB "Open" statement..

open "C:\My documents\file2.txt" for input as #1
line input #1, se1

to open the file and read the first line into "se1" variable

mail me for more info through Yahoo! Answers

Read my profile, I am the XLMan

2006-10-04 05:21:54 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers