Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Activate Open Workbooks to format

Hi All,

My VB project is coming along just fine, but I'm stuck on this on
thing.. When I open files from a listbox (multiSelect) I want to call
function to format the just opened workbooks. What happens now is tha
the called function is running on the workbook containing th
macro/form.

Instead of calling the function I've written a line to activate cel
A3, which it selects on the macro/form workbook, not the just opene
workbooks as it is supposed to.


iDestRow = 1
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then

Excel1.Visible = True
Excel1.Workbooks.Open _
Filename:=.List(i, 0), _
Format:=xlCSV, _
Delimiter:=",", _
ReadOnly:=True

Range("c3").Select


I've been thinking about using .List(i, 0) as a reference to activat
workbooks, but I can't find any info about activating workbooks o
variables...

If you need more code or info, please let me know!

Many thanks!

Joos

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel VBA - Activate Open Workbooks to format

Not sure what the Excel1 is supposed to represent - hopefully you are not
trying to open additional instances of Excel. Anyway, you can create a
reference to the workbook.

Dim wkbk as Workbook
iDestRow = 1
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then

Excel1.Visible = True
set wkbk = Excel1.Workbooks.Open( _
Filename:=.List(i, 0), _
Format:=xlCSV, _
Delimiter:=",", _
ReadOnly:=True)

wkbk.Activate
With Wkbk.Worksheets(1)
.Range("c3").NumberFormat = "$ #,##0.00"

End With

--
Regards,
Tom Ogilvy

"exceller " wrote in message
...
Hi All,

My VB project is coming along just fine, but I'm stuck on this one
thing.. When I open files from a listbox (multiSelect) I want to call a
function to format the just opened workbooks. What happens now is that
the called function is running on the workbook containing the
macro/form.

Instead of calling the function I've written a line to activate cell
A3, which it selects on the macro/form workbook, not the just opened
workbooks as it is supposed to.


iDestRow = 1
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then

Excel1.Visible = True
Excel1.Workbooks.Open _
Filename:=.List(i, 0), _
Format:=xlCSV, _
Delimiter:=",", _
ReadOnly:=True

Range("c3").Select


I've been thinking about using .List(i, 0) as a reference to activate
workbooks, but I can't find any info about activating workbooks on
variables...

If you need more code or info, please let me know!

Many thanks!

Joost


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Activate Open Workbooks to format

Thanks Tom, it works, I got a bit further yesterday. I got reall
excited but soon found out it's not exactly what I wanted. I though
that if the script when setting the cell format also activated th
workbook.

With this code I can set cell formats, even apply autofilters, but wha
I need is to activate the workbooks so that I can run a formattin
script with actions such as: adding and deleting sheets, rename sheets
apply and set autofilters, copy-paste ranges to other open workbook
and sheets.

And yes I am opening two instances of Excel at the moment, but tha
should be eliminated when I set the visibility to false?

Many thanks!!!

Joos

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Workbooks(WorkbookName).Activate Failure [email protected] Charts and Charting in Excel 2 July 16th 06 12:14 PM
When I open Excel, workbooks open automatically. How can I stop t Rhealbird Excel Discussion (Misc queries) 2 February 23rd 06 10:08 AM
Lost ability to open (activate) Excel files from Explorer, Outlook Henny Excel Discussion (Misc queries) 1 November 29th 05 05:00 PM
how do I activate links without opening external workbooks? teh_chucksta Excel Discussion (Misc queries) 0 August 29th 05 11:22 PM
Use Array to activate workbooks Stuart[_5_] Excel Programming 3 December 2nd 03 08:17 PM


All times are GMT +1. The time now is 06:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"