Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default open file from folder save in new folder


I have this code and I want it to open a file in a directory that I
choose (it does that already), and then I wunt it to create a
sub-folder in the folder I chose with the original folders name plus a
number. (example) I choose a folder named project_test then it converts
the file, in the folder, detail.htm to detail.htm.wk4. Then it creates
the sub-folder project_test0001 then saves detail.htm.wk4 in it. Then
the next time I run ConvertFiles ,when it creates the sub-folder, it
creates project_test0002, and when it has reached the tenth time it
creates it as project_test0010 etc.



Code:
--------------------


Sub ConvertFiles()
'
'
Application.DisplayAlerts = False

'
Dim vrtSelectedItem As Variant

Dim FileToOpen As String
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.Title = "Cool Application"
fd.InitialFileName = "Working"
If fd.Show = -1 Then
For a = 1 To fd.SelectedItems.Count
MsgBox fd.SelectedItems(a)
Dim NextFile As String


NextFile = Dir(fd.SelectedItems(a) & "\*detail*.htm")
Do While NextFile < ""
Workbooks.Open Filename:=NextFile
ActiveWorkbook.SaveAs Filename:= _
NextFile & ".wk4", _
FileFormat:=xlWK4, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
NextFile = Dir()


Loop
Next
End If

Application.DisplayAlerts = True


End Sub


--------------------


--
tim64
------------------------------------------------------------------------
tim64's Profile: http://www.excelforum.com/member.php...o&userid=23295
View this thread: http://www.excelforum.com/showthread...hreadid=379459

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default open file from folder save in new folder


Backup the workbooks before testing this macro

Excel version I have is 2000 so couldnot test the macro



Sub ConvertFiles()
'
'
Application.DisplayAlerts = False
Dim T As Integer
'
T = 1
Dim vrtSelectedItem As Variant

Dim FileToOpen As String
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.Title = "Cool Application"
fd.InitialFileName = "Working"
If fd.Show = -1 Then
For a = 1 To fd.SelectedItems.Count
MsgBox fd.SelectedItems(a)
Dim NextFile As String
T = 1

NextFile = Dir(fd.SelectedItems(a) & "\*detail*.htm")
Do While NextFile < ""
Workbooks.Open Filename:=NextFile

If T < 10 Then
MkDir ActiveWorkbook.Path & "\ PROJECT_TEST000" & T
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & "\ PROJECT_TEST000" & T & "\" &
ActiveWorkbook.Name & ".wk4", _
FileFormat:=xlWK4, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Else
MkDir ActiveWorkbook.Path & "\ PROJECT_TEST00" & T
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & "\ PROJECT_TEST00" & T & "\" &
ActiveWorkbook.Name & ".wk4", _
FileFormat:=xlWK4, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End If
ActiveWorkbook.Save
ActiveWorkbook.Close
NextFile = Dir()
T = T + 1

Loop
Next
End If

Application.DisplayAlerts = True


End Sub


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=379459

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default open file from folder save in new folder


it looks good, but I don't have a folder named project_test that wa
for an example, I'll have hundreds of different folders I'll use thi
in and, I'll have between 1 and 10 files in then with the name "detail
in it and, I wunt them all to go to the new folder that is created. Als
I'll probly have hundreds of folders created because I'm going to us
this alot so it will be like project_test1839(example) eventually.
Sorry I didn't clerify that earlie

--
tim6
-----------------------------------------------------------------------
tim64's Profile: http://www.excelforum.com/member.php...fo&userid=2329
View this thread: http://www.excelforum.com/showthread.php?threadid=37945

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default open file from folder save in new folder


Backup your workbooks before using this macro
Try this macro

Sub ConvertFiles()
'
'
Application.DisplayAlerts = False
Dim T As Integer
'
T = 1
Dim vrtSelectedItem As Variant

Dim FileToOpen As String
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.Title = "Cool Application"
fd.InitialFileName = "Working"
If fd.Show = -1 Then
For a = 1 To fd.SelectedItems.Count
MsgBox fd.SelectedItems(a)
Dim NextFile As String
T = 1

NextFile = Dir(fd.SelectedItems(a) & "\*detail*.htm")
Dim ar1, ar2 As Variant
ar1 = Split(fd.SelectedItems(a), "\")
ar2 = ar1(UBound(ar1))
Do While NextFile < ""
Workbooks.Open Filename:=NextFile

If T < 10 Then
MkDir ActiveWorkbook.Path & "\" & ar2 & "000" & T
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & "\" & ar2 & "000" & T & "\" &
ActiveWorkbook.Name & ".wk4", _
FileFormat:=xlWK4, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Else
MkDir ActiveWorkbook.Path & "\" & ar2 & "00" & T
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & "\" & ar2 & "00" & T & "\" &
ActiveWorkbook.Name & ".wk4", _
FileFormat:=xlWK4, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End If
ActiveWorkbook.Save
ActiveWorkbook.Close
NextFile = Dir()
T = T + 1

Loop
Next
End If

Application.DisplayAlerts = True


End Sub


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=379459

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default open file from folder save in new folder


thats almost to what I want but, when ConvertFiles runs I only want i
to create one sub-folder per run and I want all the converted files t
go into it. (example) I have four files detail1.htm, detail2.htm
detail3.htm, detail4.htm and, in the folder project_test there ar
sub-folders project_test0001 - project_test3829. So when I ru
ConvertFiles it converts the four files then it saves them to th
folder project_test3830 (after it makes it). So the next time I ru
ConvertFiles it saves the files in project_test3831 etc

--
tim6
-----------------------------------------------------------------------
tim64's Profile: http://www.excelforum.com/member.php...fo&userid=2329
View this thread: http://www.excelforum.com/showthread.php?threadid=37945



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default open file from folder save in new folder


I added 1 more function to the end



Sub ConvertFiles()
'
'
Dim temp, temp1, temp2, temp3, temp4 As Variant
Application.DisplayAlerts = False
Dim t As Integer
'
t = 1
Dim vrtSelectedItem As Variant

Dim FileToOpen As String
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.Title = "Cool Application"
fd.InitialFileName = "Working"
If fd.Show = -1 Then
For a = 1 To fd.SelectedItems.Count
Dim NextFile As String
t = 1

NextFile = Dir(fd.SelectedItems(a) & "\*detail*.htm")
Dim ar1, ar2 As Variant
ar1 = Split(fd.SelectedItems(a), "\")
ar2 = ar1(UBound(ar1))
temp = last_filename(ActiveWorkbook.Path & "\", ar2)
temp1 = Split(temp, ar2)
temp2 = CInt(temp1(1))
temp3 = temp1 + 1
temp4 = Format(temp3, "000#")
MkDir ActiveWorkbook.Path & "\" & ar2 & temp4
Do While NextFile < ""
Workbooks.Open Filename:=NextFile
ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & "\" & ar2 & temp4 & "\" &
ActiveWorkbook.Name & ".wk4", _
FileFormat:=xlWK4, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
NextFile = Dir()
t = t + 1

Loop
Next
End If

Application.DisplayAlerts = True


End Sub


Function last_filename(p As Variant, ar2 As Variant)
Dim t1 As Variant
t = Dir(p & ar2 & "*.*", vbDirectory)
While t < ""
t = Dir()
If (t < "") Then
t1 = t
End If
Wend
If t1 = "" Then
t1 = t
End If
last_filename = t1
End Function


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=379459

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
open and save an entire folder SusanWS Excel Discussion (Misc queries) 1 June 15th 06 03:56 PM
can“t change folder when open or save stian Excel Discussion (Misc queries) 0 April 21st 06 08:07 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
"Save As" folder -- can I default this to the same folder as origi Mike Excel Discussion (Misc queries) 1 June 11th 05 12:06 AM
I like to open a folder,auto print,save then close tied of opening files Excel Programming 2 April 22nd 05 10:20 PM


All times are GMT +1. The time now is 09:47 PM.

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"