Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Requesting file names

Ladies & Gents,

I use a macro which opens 3 files (A_acc.csv, A_warn.csv, & A_reject.csv),
formats & combines the files, then splits & saves them to 3 workbooks called
1_A.xls, 2_A.xls & 3_A.xls. The csv file names change daily. Other than
having to open & save each file individually, I have no problems. I wish to
update the macro so that I enter the file name, the macro then uses that
name to open the files, and save the new ones. Does anyone have any hints
that could help me?


Thanks in advance.

Andrew


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Requesting file names

Hi Andrew,

As far as I understood, you want to enter the name, which is in this
case "A" and Excel opens 3 files (A_xxx.csv), does its job,whatever it
is and saves 3 files eventually (X_A.xls).

I think following code would help you (with a little adaptation), if
you don't want to use an UserForm. I did not try it but it must work :

Sub subOpenAndSave()

On Error goto ErrorHandler

Dim xsWB1 as Workbook, xsWB2 as Workbook, xsWB3 as Workbook
Dim strFileName as String
strFileName = InputBox("Please enter filename with full path : ")
set xsWB1 = Workbooks.Open(strFileName & "acc.csv")
set xsWB2 = Workbooks.Open(strFileName & "warn.csv")
set xsWB3 = Workbooks.Open(strFileName & "reject.csv")

...
' Here happens what you want to do with them
...

xsWB1.SaveAs FileName:= "1_" & strFileName
xsWB2.SaveAs FileName:= "2_" & strFileName
xsWB3.SaveAs FileName:= "3_" & strFileName

'and if you want to close them :
'xsWB1.Close
'...

Exit Sub

ErrorHandler :
if Err.Number = 1004 then
msgbox "File not found...exiting"
else
msgbox "unknown error...exiting"
end if

End Sub


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Requesting file names

Tolag,

Thanks for that. I'll give it a try, and see how I go. I certainly like
the error handler; I've never used one in any of my macros before. I
certainly can have some fun with that. :-)


Thanks again.

"tolgag " wrote in message
...
Hi Andrew,

As far as I understood, you want to enter the name, which is in this
case "A" and Excel opens 3 files (A_xxx.csv), does its job,whatever it
is and saves 3 files eventually (X_A.xls).

I think following code would help you (with a little adaptation), if
you don't want to use an UserForm. I did not try it but it must work :

Sub subOpenAndSave()

On Error goto ErrorHandler

Dim xsWB1 as Workbook, xsWB2 as Workbook, xsWB3 as Workbook
Dim strFileName as String
strFileName = InputBox("Please enter filename with full path : ")
set xsWB1 = Workbooks.Open(strFileName & "acc.csv")
set xsWB2 = Workbooks.Open(strFileName & "warn.csv")
set xsWB3 = Workbooks.Open(strFileName & "reject.csv")

..
' Here happens what you want to do with them
..

xsWB1.SaveAs FileName:= "1_" & strFileName
xsWB2.SaveAs FileName:= "2_" & strFileName
xsWB3.SaveAs FileName:= "3_" & strFileName

'and if you want to close them :
'xsWB1.Close
'...

Exit Sub

ErrorHandler :
if Err.Number = 1004 then
msgbox "File not found...exiting"
else
msgbox "unknown error...exiting"
end if

End Sub


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Requesting Assistance with Embedding Word documents into xcel File Mkate Excel Discussion (Misc queries) 0 November 4th 08 09:32 PM
This should be easy, but can't find an answer...requesting your in Lisa Excel Worksheet Functions 1 January 23rd 08 06:02 AM
Requesting virus scan Alan Beban[_2_] Excel Discussion (Misc queries) 6 September 1st 07 02:03 AM
Requesting sync to Excel2007 mobile Jonathan Excel Discussion (Misc queries) 0 January 10th 07 01:54 AM
Requesting Help Scooterdog Excel Worksheet Functions 2 November 10th 04 06:18 PM


All times are GMT +1. The time now is 03:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"