Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Folder and file name
#4
Solved: 10 Years, 9 Months, 2 Weeks ago
Hi Shruti,

If i have understood correctly, you want create a folder and inside that folder create an excel file, write some data in the excel file and save it, all dynamically. If that is the case, the code below might help you achieve that:

Code:
Dim folderPath, folderName, xlFileName

//Provide folder path, folder name and excel file name

folderPath = "C:\"
folderName = "MyFolder"
xlFileName = "MyExcel.xls"

//Create File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
//Build the folder path
newPath = fso.BuildPath(folderPath,folderName)

//Create the folder if it is not created already
If fso.FolderExists(newPath) <> True Then
    fso.CreateFolder(newPath)
End If

//Create Excel object
Set xlApp = CreateObject("Excel.Application")
Set xlSheet=createObject("Excel.sheet")

//Write into excel file and save it inside the newly created folder
xlSheet.ActiveSheet.cells(1,1).value=1111
xlSheet.SaveAs newPath&"\"&xlFileName

Set xlSheet = Nothing
Set xlApp = Nothing
Set fso = Nothing

Hope this helps you. Also hope next time around you spell my name correct Smile
Reply


Messages In This Thread
Folder and file name - by shruti - 12-06-2011, 11:13 AM
RE: Folder and file name - by PrabhatN - 12-06-2011, 11:57 AM
RE: Folder and file name - by shruti - 12-06-2011, 02:08 PM
RE: Folder and file name - by PrabhatN - 12-06-2011, 02:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Executing via create "RES"xx folder? nishitd 0 1,120 03-07-2018, 01:09 AM
Last Post: nishitd
  code for validation to create a sub folder smiley 0 1,437 10-19-2016, 10:08 PM
Last Post: smiley
  Extract and save a file from zip folder using VB Script karthicksri07 1 6,203 06-29-2016, 02:19 PM
Last Post: Ankesh
  [UFT] Close opened folder robertosalemi 1 3,164 02-10-2016, 07:06 PM
Last Post: robertosalemi
  Run scripts from folder badri 1 2,655 11-26-2014, 06:18 PM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 1 Guest(s)