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
#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


Messages In This Thread
RE: How to identify the object reference to the existing(already opened) Excel sheet - by krr - 09-26-2012, 07:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to identify an webelement object Ninjukp 0 2,106 01-10-2018, 09:25 PM
Last Post: Ninjukp
  Pass reference to datatable into function smallsteve 2 1,898 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,597 01-17-2017, 11:05 AM
Last Post: JACKSPARROW
  Not Able to Identify Object during Recovery Scenario Phani 2 3,108 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,517 01-11-2016, 12:45 PM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 1 Guest(s)