View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
hshayh0rn hshayh0rn is offline
external usenet poster
 
Posts: 74
Default Code to make a sheet active

I appreciate your help Bob but I'm by no means a programmer so I'm getting a
little lost in the process here. I'm getting a compile error for the line:

Set aryWBs(i) = Workbooks.Open FName(i)

Also, I don't see how this code will help me activate the worksheet I
mentioned in my initial post. Opening the files is working great and I can
use 3 of thr 4 right now. I just can't seem to figure our or understand from
everyone who has tried to me how to write the code to activate (and use) the
fourth workbook/sheet.


"Bob Phillips" wrote:

I would use an array of objects

Public Sub OpenFiles()

On Error GoTo ErrorHandler

Dim FName As Variant
Dim i As Long
Dim aryWBs
FName = Application.GetOpenFilename _
("CSV Files,*.csv", _
MultiSelect:=True)


Redim aryWBs(LBound(FName) To UBound(FName))
For i = LBound(FName) To UBound(FName)
Set aryWBs(i) = Workbooks.Open FName(i)
Application.ScreenUpdating = False

'With Application 'disable the automatic calc feature
'.Calculation = xlManual
'.MaxChange = 0.001
'End With

'Reset Cursor position

Next

ErrorHandler:

End Sub


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"hshayh0rn" wrote in message
...
Bob,

here is the code I'm using to open the files.

Public Sub OpenFiles()

On Error GoTo ErrorHandler

Dim FName As Variant
Dim i As Long

FName = Application.GetOpenFilename _
("CSV Files,*.csv", _
MultiSelect:=True)


For i = LBound(FName) To UBound(FName)
Workbooks.Open FName(i)
Application.ScreenUpdating = False

'With Application 'disable the automatic calc feature
'.Calculation = xlManual
'.MaxChange = 0.001
'End With

'Reset Cursor position

Next

ErrorHandler:

End Sub

I require the users to open four files. Three of the four have names that
are generic and easy to use but it's the fourth one I'm having the trouble
with. Looking at the code above that I use to open the files how can I set
the object variable?

"Bob Phillips" wrote:

When you open the workbook, set an object variable

Set oWB = Workbooks.Open Filename:= ... etc

and then use that object variable when activating.

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"hshayh0rn" wrote in message
...
I have an active worksheet in a workbook that I need to grab some data

off
of. The problem is the name of the workbook that the worksheet resides

in
contains a date and time the workbook was created as part of the file
name.
I've tried to use wildcards* to acftivate the workbook but that

doesn't
seem
to work. Here is an example of the code I'm trying to run that isn't
working:

Windows(BankNum & "-UserGroupReport" * ".csv").Activate

BankNum comes from user input
-UserGroupReport is static in the name
* represents the part of the file name that contains the date/time

I don't want to make this really complicated. Does anyone have any

ideas?