Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Excel Automation and columns width


Reply
 
Thread Tools Display Modes
  #1  
Old 09-17-2005, 07:24 AM
LG-2005 LG-2005 is offline
Newcomer
 
Join Date: May 2005
Posts: 10
Default Excel Automation and columns width


Hello
I used VB6 to display reports in Ms excel 2003. but I have a problem with the columns width. I wrote this code to control the width: (for example)
Code:
xlsheet.Columns("A:A").ColumnWidth = 2.29
the problem is that this width depends on the computer I am working on. i.e they fit perfectly on this PC but they are too wide in the any other PC even though the width is the same 2.29
Is there a way around this problem?
Reply With Quote
  #2  
Old 09-17-2005, 09:59 AM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

Do you mean they are to wide for the screen resolution in use, or are they really diplayed wider, though their width is set to 2.29?
Reply With Quote
  #3  
Old 09-18-2005, 02:07 AM
LG-2005 LG-2005 is offline
Newcomer
 
Join Date: May 2005
Posts: 10
Default

Quote:
Originally Posted by italkid
Do you mean they are to wide for the screen resolution in use, or are they really diplayed wider, though their width is set to 2.29?
the resolution is no the problem, they are displayed wider, though their width is set to 2.29!
is that unusual?
Reply With Quote
  #4  
Old 09-18-2005, 02:31 AM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

Quote:
Originally Posted by LG-2005
is that unusual?
I've never heard about this kind of issue, nor was I able to find info about it... Does it also happen if you try to replicate the problem with a new and blank file? Any differences in Excel version or installed service packs between your pc and the others?
Reply With Quote
  #5  
Old 09-18-2005, 08:21 AM
LG-2005 LG-2005 is offline
Newcomer
 
Join Date: May 2005
Posts: 10
Default

Quote:
Originally Posted by italkid
Does it also happen if you try to replicate the problem with a new and blank file
i'll try that and tell you what happened

Quote:
Originally Posted by italkid
Any differences in Excel version or installed service packs between your pc and the others?
Excel version is the same. i use two different OP in two different computers: Xp professional and XP Home both service pack 2.
Reply With Quote
  #6  
Old 09-19-2005, 08:45 AM
LG-2005 LG-2005 is offline
Newcomer
 
Join Date: May 2005
Posts: 10
Default

Hello:
Sorry for the delay.
The only way I can now that the width is not the same is that the columns in one PC are contained in one page and two pages in the other.
If I use the 1st PC to generate the Excel file and try to display it in the 2nd PC, I won’t have this problem. It happens only when I use my VB program which specify the width of the columns.
I tried to use the autofit command, so it will fit the width of the columns around the text but it is giving me an error: Autofit method of Range class failed.

xlsheet.Columns("A:BZ").AutoFit

is that because there are some empty cells? If so is there some other command I can use?
Reply With Quote
  #7  
Old 09-19-2005, 12:17 PM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

Autofit should not result in an error neither, as that command does automatically ignore empty columns... That sheet is not protected?
Reply With Quote
  #8  
Old 09-19-2005, 04:49 PM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

I think Autofit may fail if the range has merged cells.
Reply With Quote
  #9  
Old 09-20-2005, 03:31 AM
LG-2005 LG-2005 is offline
Newcomer
 
Join Date: May 2005
Posts: 10
Default

Quote:
Originally Posted by italkid
IThat sheet is not protected?.
Bingo!

Thank You italkid for your help.


Quote:
Originally Posted by herilane
I think Autofit may fail if the range has merged cells.
No, i have not merged the cells. the problem was that i wrote the protection command before the autofit command. thanks anyway.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->