Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default column widths

I have the following line code that copies the column
widths from one workbook to another but doesn't seem to be
working:

cwkb.activesheet.columns("A:AW").columnwidth =
thisworkbook.worksheets(1).columns("A:AW").columnw idth

I think that there is something simpler than this.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default column widths

Steven,

How is it not working? Are you getting an error? Could it be that cwkb
workbook is not active? If it is, you probably don't need the cwkb
qualifier. If it isn't, you can't use Activesheet, but must use a sheet name
or index.

--

HTH

Bob Phillips

"Steven Cheng" wrote in message
...
I have the following line code that copies the column
widths from one workbook to another but doesn't seem to be
working:

cwkb.activesheet.columns("A:AW").columnwidth =
thisworkbook.worksheets(1).columns("A:AW").columnw idth

I think that there is something simpler than this.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default column widths

I think when Bob was testing, all the columnwidths in his "from" worksheet were
the same width.

When they were different widths, your code failed for me.

So if you have xl2k or higher, you could copy|paste special columnWidths:

Option Explicit
Sub testme03()

Dim cwkb As Workbook
Set cwkb = Workbooks("book2")

cwkb.ActiveSheet.Columns("A:AW").Copy
ThisWorkbook.Worksheets(1).Columns("A:AW").PasteSp ecial _
Paste:=xlPasteColumnWidths
'paste:=8 'in xl2k--bug in the documentation

Application.CutCopyMode = False

End Sub

And if you're using xl97, I think you'll have to loop through the columns:

Option Explicit
Sub testme03()

Dim cwkb As Workbook
Dim myCol As Range
Set cwkb = Workbooks("book2")

For Each myCol In cwkb.ActiveSheet.Columns("A:AW")
ThisWorkbook.Worksheets(1).Columns(myCol.Address). ColumnWidth _
= myCol.ColumnWidth
Next myCol

End Sub

And I've never used activesheet as anything as a property of the application.
But it's also a property of a workbook and window. So that shouldn't cause a
problem. Although, I'd be scared that the activesheet wasn't the one I really
wanted.)


Steven Cheng wrote:

Bob;

There must be something else that I am missing because I
have tried to remove cwkb qualifier and it still doesn't
work.

Could you send me your test file with the coding.

Steven
-----Original Message-----
Steven,

I setup a simple test, and just used ACtivesheet without

a workbook
qualifier, and it worked okay.

--

HTH

Bob Phillips

"Steven Cheng" wrote in message
...
Sorry, I should have clarified that the "error" is
specifically that the column widths are not copying over
from worksheet1 to cwkb.

There are other pieces to this procedure specifically

that
cwkb should be the active workbook as it has been just
added prior to the column width function.

Steven
-----Original Message-----
Steven,

How is it not working? Are you getting an error? Could

it
be that cwkb
workbook is not active? If it is, you probably don't

need
the cwkb
qualifier. If it isn't, you can't use Activesheet, but
must use a sheet name
or index.

--

HTH

Bob Phillips

"Steven Cheng" wrote in message
...
I have the following line code that copies the column
widths from one workbook to another but doesn't seem

to
be
working:

cwkb.activesheet.columns("A:AW").columnwidth =
thisworkbook.worksheets(1).columns

("A:AW").columnwidth

I think that there is something simpler than this.


.



.


--

Dave Peterson

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
Different widths for each column in a 100% stacked column chart Chart Explorer Charts and Charting in Excel 1 May 21st 09 09:19 AM
Different column widths? NorCalHomeFinance Setting up and Configuration of Excel 2 August 9th 08 09:16 PM
One column with various widths RichardGolf72 Excel Worksheet Functions 2 June 7th 06 07:54 PM
Column Widths Pricklyflower Excel Discussion (Misc queries) 4 March 1st 06 09:48 PM
Column widths are the same but look different. Suzan Excel Discussion (Misc queries) 0 December 29th 05 04:29 PM


All times are GMT +1. The time now is 03:52 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"