Workbook Syntax

  • Thread starter Thread starter MFRASER
  • Start date Start date
M

MFRASER

How do I access a sheet in a different workbok?

Say for example my excel project does the following

dim DataWorkBook as Workbook
dim currentWorkBook as Workbook

Set currentWorkBook = ActiveWorkbook

Set DataWorkBook = Application.Workbooks.Add
DataWorkBook.Name = DataSheetTitle

currentWorkBook.Activate

'I want to access a cell or range inside of DataworkBook
 
One way:

Dim DataWorkBook As Workbook
Dim currentWorkBook As Workbook

Set currentWorkBook = ActiveWorkbook
Set DataWorkBook = Application.Workbooks.Add

With DataWorkBook
.Sheets("Sheet1").Range("A1").Value = _
currentWorkBook.Sheets("Sheet2").Range("J10").Value
.SaveAs Filename:=DataSheetTitle
End With
 
Back
Top