Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
kk kk is offline
external usenet poster
 
Posts: 2
Default file operations

hi

Are file operations possible as part of Excel macros?

Looking for something similar to what's available in a batch file.

e.g.

create folder
move or copy file

Vivek


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default file operations

Vivek, check out this page from Tek Tips, it has some really good info.
http://www.tek-tips.com/faqs.cfm?fid=4116

Charles

kk wrote:
hi

Are file operations possible as part of Excel macros?

Looking for something similar to what's available in a batch file.

e.g.

create folder
move or copy file

Vivek


  #3   Report Post  
Posted to microsoft.public.excel.programming
kk kk is offline
external usenet poster
 
Posts: 2
Default file operations

Hey Charles,

Looks good. Thanks.

Vivek

"Die_Another_Day" wrote in message
ups.com...
Vivek, check out this page from Tek Tips, it has some really good info.
http://www.tek-tips.com/faqs.cfm?fid=4116

Charles

kk wrote:
hi

Are file operations possible as part of Excel macros?

Looking for something similar to what's available in a batch file.

e.g.

create folder
move or copy file

Vivek




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default file operations

There are also built in function in VBA

mkdir
chdir
kill
filecopy
name (moves a file)
many others.

--
Regards,
Tom Ogilvy


"kk" wrote:

Hey Charles,

Looks good. Thanks.

Vivek

"Die_Another_Day" wrote in message
ups.com...
Vivek, check out this page from Tek Tips, it has some really good info.
http://www.tek-tips.com/faqs.cfm?fid=4116

Charles

kk wrote:
hi

Are file operations possible as part of Excel macros?

Looking for something similar to what's available in a batch file.

e.g.

create folder
move or copy file

Vivek





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default file operations

Tom, what is the best way to check for an existing file/directory? The
DIR function?

Charles
Tom Ogilvy wrote:
There are also built in function in VBA

mkdir
chdir
kill
filecopy
name (moves a file)
many others.

--
Regards,
Tom Ogilvy


"kk" wrote:

Hey Charles,

Looks good. Thanks.

Vivek

"Die_Another_Day" wrote in message
ups.com...
Vivek, check out this page from Tek Tips, it has some really good info.
http://www.tek-tips.com/faqs.cfm?fid=4116

Charles

kk wrote:
hi

Are file operations possible as part of Excel macros?

Looking for something similar to what's available in a batch file.

e.g.

create folder
move or copy file

Vivek







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default file operations

the most robust way is with the filesystem object, but dir can be used as
well. The problem with dir is that if used thoughtlessly it can provide
misleading results if there is a file name with no extension that matches the
directory inquired about (and that directory does not exist).


Option Explicit


Sub Tester2()
Dim rw As Long
Dim ilevel As Long
Dim sPath As String
Dim Drive As String
Dim AnyName As String
Dim Volume As String
Dim i As Integer


Drive = InputBox("Enter Drive to Catalog" & _
vbCrLf & "(ie. D or d) ")
If Trim(Drive) = "" Then Exit Sub
Drive = StrConv(Drive, vbUpperCase)
Drive = Drive & ":\"


Dim sArr() As String
ReDim sArr(1 To 1)
rw = 1
ilevel = 1
Cells(rw, ilevel) = Dir(Drive, vbVolume)
rw = rw + 1
Cells(rw, ilevel) = "\"
rw = rw + 1
AnyName = Dir(Drive, vbDirectory)
Do While AnyName < ""
If AnyName < "." And AnyName < ".." _
And GetAttr("H:\" & AnyName) = vbDirectory Then
sArr(UBound(sArr)) = AnyName
ReDim Preserve sArr(1 To UBound(sArr) + 1)
End If
AnyName = Dir()
Loop
ilevel = ilevel + 1
For i = 1 To UBound(sArr) - 1
AnyName = sArr(i)
Cells(rw, ilevel) = AnyName
rw = rw + 1
sPath = Drive & AnyName & "\"
GetSubs sPath, rw, ilevel
Next


AnyName = Dir(Drive, vbNormal)
Do While AnyName < ""
Cells(rw, ilevel) = AnyName
rw = rw + 1
AnyName = Dir()
Loop
End Sub


Sub GetSubs(sPath As String, _
rw As Long, ilevel As Long)
Dim sName As String
Dim i As Long
Dim sArr()


ReDim sArr(1 To 1)
sName = Dir(sPath, vbDirectory)
Do While sName < ""
If sName < "." And sName < ".." And _
GetAttr(sPath & sName) = vbDirectory Then
sArr(UBound(sArr)) = sName
ReDim Preserve sArr(1 To UBound(sArr) + 1)
End If
sName = Dir()
Loop
For i = 1 To UBound(sArr) - 1
sName = sArr(i)
Cells(rw, ilevel + 1) = sName
rw = rw + 1
GetSubs sPath & sName & "\", rw, ilevel + 1
Next i
sName = Dir(sPath, vbNormal)
Do While sName < ""
Cells(rw, ilevel + 1) = sName
rw = rw + 1
sName = Dir()
Loop
End Sub


is some old code that is illustrative.

--
Regards,
Tom Ogilvy



"Die_Another_Day" wrote:

Tom, what is the best way to check for an existing file/directory? The
DIR function?

Charles
Tom Ogilvy wrote:
There are also built in function in VBA

mkdir
chdir
kill
filecopy
name (moves a file)
many others.

--
Regards,
Tom Ogilvy


"kk" wrote:

Hey Charles,

Looks good. Thanks.

Vivek

"Die_Another_Day" wrote in message
ups.com...
Vivek, check out this page from Tek Tips, it has some really good info.
http://www.tek-tips.com/faqs.cfm?fid=4116

Charles

kk wrote:
hi

Are file operations possible as part of Excel macros?

Looking for something similar to what's available in a batch file.

e.g.

create folder
move or copy file

Vivek






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default file operations

of course if your intent is to create it if it doesn't, there is no need to
check

On Error Resume Next
MkDir "C:\Mydir"
On Error goto 0

of course if it is multi tiered and you don't know if all the tiers are
there, it is more complex.

--
Regards,
Tom Ogilvy


"Die_Another_Day" wrote:

Tom, what is the best way to check for an existing file/directory? The
DIR function?

Charles
Tom Ogilvy wrote:
There are also built in function in VBA

mkdir
chdir
kill
filecopy
name (moves a file)
many others.

--
Regards,
Tom Ogilvy


"kk" wrote:

Hey Charles,

Looks good. Thanks.

Vivek

"Die_Another_Day" wrote in message
ups.com...
Vivek, check out this page from Tek Tips, it has some really good info.
http://www.tek-tips.com/faqs.cfm?fid=4116

Charles

kk wrote:
hi

Are file operations possible as part of Excel macros?

Looking for something similar to what's available in a batch file.

e.g.

create folder
move or copy file

Vivek






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
IF Calculation and Operations Rich Excel Discussion (Misc queries) 3 February 3rd 09 10:37 PM
Repeat Operations Adam1 Chicago Excel Discussion (Misc queries) 4 January 25th 07 04:31 PM
Operations on .DAT file in Excel... steveB Excel Programming 0 May 26th 04 12:00 AM
operations on ranges rene.lenaers Excel Programming 2 October 18th 03 06:26 AM
Help With Worksheet Operations Justin Starnes Excel Programming 3 July 31st 03 04:25 AM


All times are GMT +1. The time now is 11:58 PM.

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

About Us

"It's about Microsoft Excel"