Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to identify the object reference to the existing(already opened) Excel sheet
#1
Not Solved
How to identify the object reference to the existing(already opened) Excel sheet in the Desktop and do"save as" of that file.I need to identify the existing(already opened) excel file in the desktop and do "save as" of that file in the designated folder. Please help me in getting VB Script code for this.

I have tried the below code, but its not working.

I am using Excel 2010.



Code:
Dim fso, FolderPath, objExcel, strPathExcel

      FolderPath = "c:\Excel_Reports"

      strPathExcel = FolderPath&"abcd.xls"

   ' Get instance of FileSystemObject.

   Set fso = CreateObject("Scripting.FileSystemObject")


    Set objExcel = GetObject("","Excel.Application")

      If not(fso.FolderExists(FolderPath)) then
       fso.CreateFolder (FolderPath)
          ' Create a new folder with the FileSystemObject object.
       End if

  objExcel.ActiveWorkbook.saveas strPathExcel
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
Reply
#2
Not Solved
You can use below code,

Code:
Dim fso, FolderPath, objExcel, strPathExcel

FolderPath = "C:\Users\Desktop\"

strPathExcel = FolderPath&"abcd.xls"

' Get instance of FileSystemObject.

Set fso = CreateObject("Scripting.FileSystemObject")


Set objExcel = GetObject("C:\Users\Desktop\xyz.xls","")''you should provide the path of the already opened sheet. Else if you want to work with your code you need to create an object of the work sheet and then use.

If not(fso.FolderExists(FolderPath)) then
fso.CreateFolder (FolderPath)
' Create a new folder with the FileSystemObject object.
End if

objExcel.saveas strPathExcel
objExcel.Close
objExcel.Quit

You can use below code with minimal changes to your code. you can use in both ways.

Code:
Dim fso, FolderPath, objExcel, strPathExcel

FolderPath = "C:\Users\Desktop\"

strPathExcel = FolderPath&"abcd.xls"

' Get instance of FileSystemObject.

Set fso = CreateObject("Scripting.FileSystemObject")


Set objExcel = GetObject("","Excel.Application")
Set objWorkBook = objExcel.Workbooks.Open ("C:\Users\Desktop\xyz.xls")''Already opened excel path

If not(fso.FolderExists(FolderPath)) then
fso.CreateFolder (FolderPath)
' Create a new folder with the FileSystemObject object.
End if

objExcel.ActiveWorkbook.saveas strPathExcel
objExcel.ActiveWorkbook.Close
objExcel.quit

Hi, Yogesh you can use below code.
Code:
Dim fso, FolderPath, objExcel, strPathExcel

FolderPath = "C:\Users\Desktop\"

strPathExcel = FolderPath&"abcd.xls"

' Get instance of FileSystemObject.

Set fso = CreateObject("Scripting.FileSystemObject")


Set objExcel = GetObject("","Excel.Application")
Set objWorkBook = objExcel.Workbooks.Open ("C:\Users\Desktop\xyz.xls")''already opened file

If not(fso.FolderExists(FolderPath)) then
fso.CreateFolder (FolderPath)
' Create a new folder with the FileSystemObject object.
End if

objExcel.ActiveWorkbook.saveas strPathExcel
objExcel.ActiveWorkbook.Close
objExcel.quit
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to identify an webelement object Ninjukp 0 2,097 01-10-2018, 09:25 PM
Last Post: Ninjukp
  Pass reference to datatable into function smallsteve 2 1,884 09-28-2017, 09:18 PM
Last Post: smallsteve
  Trying to create List box in excel sheet at Run time with values yes No JACKSPARROW 0 1,589 01-17-2017, 11:05 AM
Last Post: JACKSPARROW
  Not Able to Identify Object during Recovery Scenario Phani 2 3,090 01-25-2016, 01:26 PM
Last Post: arunshuklainbox
  UFT 12.02 Compatibility for IE 11.0 : Fail to identify the defined Object Amruta_121 9 10,483 01-11-2016, 12:45 PM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 1 Guest(s)