PC Review


Reply
Thread Tools Rate Thread

Creating a folder using Visual Basic HELP!!!

 
 
=?Utf-8?B?RGFuTXNvZUVF?=
Guest
Posts: n/a
 
      2nd Jul 2007
I'm very new to visual basic and I was wondering how do I create a folder and
place the modified file from the macro into that new folder. Here's my code
so far. I would also like to name the folder and file to they day that the
macro is run if that's possible?

Option Explicit


Sub CRautomate()

'Application.OnTime TimeValue("012:49:00"), "CRautomate"


'-----------Declare all variables-----
Dim Col As Integer
Dim Row As Integer

Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

Dim newBook As Workbook
Dim newSheet As Worksheet

Workbooks.Open "I:\SW\users\CR Prioritization\Raw Data\template" 'Open
template file with dropdown menus

'--------Populate the spreadsheet----------------------------
Row = 1
Do Until Row = 25

For Col = 1 To 35
ActiveSheet.Cells(Row, Col) = Data.Cells((8 + Row), Col).Value

Next
Row = Row + 1
If Row = 2 Then Row = 3 'gets rid of .... field

Loop

ActiveSheet.Columns("B").Hidden = False 'unhide columns
ActiveSheet.Columns("D").ColumnWidth = 20 'make column D visible
ActiveSheet.Rows(2).Delete

With Application.FileSearch
.NewSearch
.FileType = msoFileTypeExcelWorkbooks
.LookIn = "I:\SW\users\CR Prioritization"
.SearchSubFolders = True
End With




ActiveSheet.SaveAs "I:\SW\users\CR Prioritization\Automation Test
Folder\Open CR List" 'output file

Workbooks("Open CR List.xls").Close 'close the file which was opened

End Sub

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      2nd Jul 2007
Dim ExistingFolderName as string
Dim NewFolderName as string

existingfoldername = "I:\SW\users\CR Prioritization\Automation Test Folder"
if right(existingfoldername, 1) <> "\" then
existingfoldername = existingfoldername & "\"
end if

'no slashes in that date format!
newfoldername = existingfoldername & format(date,"yyyy_mm_dd")

on error resume next 'in case the folder can't be made
mkdir newfoldername
if err.number <> 0 then
msgbox "error creating folder!"
err.clear
end if



DanMsoeEE wrote:
>
> I'm very new to visual basic and I was wondering how do I create a folder and
> place the modified file from the macro into that new folder. Here's my code
> so far. I would also like to name the folder and file to they day that the
> macro is run if that's possible?
>
> Option Explicit
>
> Sub CRautomate()
>
> 'Application.OnTime TimeValue("012:49:00"), "CRautomate"
>
> '-----------Declare all variables-----
> Dim Col As Integer
> Dim Row As Integer
>
> Dim oExcel As Object
> Dim oBook As Object
> Dim oSheet As Object
>
> Dim newBook As Workbook
> Dim newSheet As Worksheet
>
> Workbooks.Open "I:\SW\users\CR Prioritization\Raw Data\template" 'Open
> template file with dropdown menus
>
> '--------Populate the spreadsheet----------------------------
> Row = 1
> Do Until Row = 25
>
> For Col = 1 To 35
> ActiveSheet.Cells(Row, Col) = Data.Cells((8 + Row), Col).Value
>
> Next
> Row = Row + 1
> If Row = 2 Then Row = 3 'gets rid of .... field
>
> Loop
>
> ActiveSheet.Columns("B").Hidden = False 'unhide columns
> ActiveSheet.Columns("D").ColumnWidth = 20 'make column D visible
> ActiveSheet.Rows(2).Delete
>
> With Application.FileSearch
> .NewSearch
> .FileType = msoFileTypeExcelWorkbooks
> .LookIn = "I:\SW\users\CR Prioritization"
> .SearchSubFolders = True
> End With
>
>
>
>
> ActiveSheet.SaveAs "I:\SW\users\CR Prioritization\Automation Test
> Folder\Open CR List" 'output file
>
> Workbooks("Open CR List.xls").Close 'close the file which was opened
>
> End Sub


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Visual Basic Macro Clarence Microsoft Excel Misc 1 24th Mar 2010 08:06 PM
How to Creating HTML file in Visual Basic.NET DLL pari kanaga Microsoft ASP .NET 1 19th Apr 2005 03:26 PM
Creating Autorun CD using Visual Basic David Ogden Microsoft Powerpoint 4 12th Oct 2004 05:39 PM
creating webapplication in visual basic.net =?Utf-8?B?ZmFy?= Microsoft ASP .NET 1 4th Apr 2004 02:08 PM
Creating a new Calendar appointment in Visual Basic hoan Microsoft Outlook VBA Programming 1 25th Nov 2003 02:52 PM


Features
 

Advertising
 

Newsgroups
 


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