Copy data from another Excel from a specific Sheet

Vagelisr

New Member
Joined
Sep 22, 2016
Messages
28
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hi to all

I want to open a specific folder, find all Excel and from a specific Sheet take a parm cell value

The problem is i cant open the specific sheet and i need your help

All the others work without issues

The code (Function) i use to open the other excel and copy the specific cell is this

Code:
Function OpenExcelFile(PathFolderName) As String
    Dim objExcel As Object, objWorkbook As Object
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open(PathFolderName)

[I][B]    ActiveSheet.Name = TabName[/B][/I]

    OpenExcelFile = objExcel.ActiveSheet.Range(CellName)
    objWorkbook.Close False 'savechanges:=false
    Set objExcel = Nothing
    Set objWorkbook = Nothing
End Function

The Bold line is where i try to change to the sheet i want but of course is wrong
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
All that line of code is going to do is try to change the name of the active sheet in the workbook you've just opened.

What worksheet in the workbooks you are opening do you want to copy the value/values from?
 
Upvote 0
First of all thanks for your quick responce.

Yes i know this (i understand first time i run the code)

I want to open the "PathFolderName" (Path with excel the file)
and after this to open a specific sheet. with parameter name TabName
 
Upvote 0
I change the code to this one

Code:
Function OpenExcelFile(PathFolderName) As String
    Dim objExcel As Object, objWorkbook As Object
    Dim objWorksheet As Excel.Worksheet
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open(PathFolderName)
    Set objWorksheet = objWorkbook.Worksheets(TabName)
    OpenExcelFile = objExcel.ActiveSheet.Range(CellName)
    objWorkbook.Close False 'savechanges:=false
    Set objExcel = Nothing
    Set objWorkbook = Nothing
    Set objWorksheet = Nothing
End Function

But again they did not open the sheet i want
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,783
Members
449,188
Latest member
Hoffk036

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top