Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Different widths for each column in a 100% stacked column chart | Charts and Charting in Excel | |||
Different column widths? | Setting up and Configuration of Excel | |||
One column with various widths | Excel Worksheet Functions | |||
Column Widths | Excel Discussion (Misc queries) | |||
Column widths are the same but look different. | Excel Discussion (Misc queries) |