Activating different Workbooks

N

Neeru

Hi,

In Excel VBA Programming I am unable to activate the
worksheet with the activate property.

My code is something like this :

Public macrotemp As Variant
Public ExcelFile As Variant

Sub OpenOneFile()

ExcelFile = Application.GetOpenFilename("Excel-
files,*.xls", _
1, "Select One File To Open", , False)
If TypeName(ExcelFile) = "Boolean" Then Exit Sub

Debug.Print "Selected file: " & ExcelFile
Workbooks.Open ExcelFile
End Sub

Sub SaveOneFile()
Dim Wk As Workbook
Set Wk = Workbooks.Add

macrotemp = Application.GetSaveAsFilename
("MyFileName.xls", _
"Excel files,*.xls", 1, "Select your folder and
filename for the Output file")
If TypeName(macrotemp) = "Boolean" Then Exit Sub

Wk.SaveAs macrotemp
End Sub

Sub mainprog()
OpenOneFile
ExcelSheet = InputBox("Please Enter the Name of the
Excel Sheet where the Data is Present: ")

SaveOneFile

Workbooks(ExcelFile).Worksheets(ExcelSheet).Activate
x = Range("D" & 20).Value

MsgBox (x)
End Sub


The activate property of the worksheet is giving the
error "script out of range". How do i solve this ??

I would appreciate any help.
Thanks,
Neeru.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top