PC Review


Reply
Thread Tools Rate Thread

How to change column size in VB6 and Excel 2002

 
 
Tony Girgenti
Guest
Posts: n/a
 
      16th Jan 2008
Hello.

Using VB6.0 and Excel 2002. I'm trying to change the column width of a
column before saving the workbook. I can do other changes to the worksheet,
like fonts and values etc., but it won't change the columnwidth.

I tried these statements and none of them work:
oSheet.Range("A1").Columns.ColumnWidth = 5.75
oSheet.Range("A1").ColumnWidth = 5.75
oSheet.Columns("A:A").ColumnWidth = 5.75

oSheet.Columns("A").Select
Selection.ColumnWidth = 5.75

Does anybody know how to do this?

Any help would be gratefully appreciated.

Thanks,
Tony
 
Reply With Quote
 
 
 
 
GTVT06
Guest
Posts: n/a
 
      16th Jan 2008
On Jan 15, 8:21*pm, Tony Girgenti <tony(nospam)@lakesideos.com> wrote:
> Hello.
>
> Using VB6.0 and Excel 2002. *I'm trying to change the column width of a
> column before saving the workbook. *I can do other changes to the worksheet,
> like fonts and values etc., but it won't change the columnwidth.
>
> I tried these statements and none of them work:
> * * * * oSheet.Range("A1").Columns.ColumnWidth = 5.75
> * * * * oSheet.Range("A1").ColumnWidth = 5.75
> * * * * oSheet.Columns("A:A").ColumnWidth = 5.75
>
> * * * * oSheet.Columns("A").Select
> * * * * Selection.ColumnWidth = 5.75
>
> Does anybody know how to do this?
>
> Any help would be gratefully appreciated.
>
> Thanks,
> Tony


Try:

Sheets("oSheet").Columns("A:A").ColumnWidth = 5.75
 
Reply With Quote
 
Tony Girgenti
Guest
Posts: n/a
 
      16th Jan 2008
Hello GTVT06.

I'm getting Subscript out of range when i try your code.

Thanks,
Tony

"GTVT06" wrote:

> On Jan 15, 8:21 pm, Tony Girgenti <tony(nospam)@lakesideos.com> wrote:
> > Hello.
> >
> > Using VB6.0 and Excel 2002. I'm trying to change the column width of a
> > column before saving the workbook. I can do other changes to the worksheet,
> > like fonts and values etc., but it won't change the columnwidth.
> >
> > I tried these statements and none of them work:
> > oSheet.Range("A1").Columns.ColumnWidth = 5.75
> > oSheet.Range("A1").ColumnWidth = 5.75
> > oSheet.Columns("A:A").ColumnWidth = 5.75
> >
> > oSheet.Columns("A").Select
> > Selection.ColumnWidth = 5.75
> >
> > Does anybody know how to do this?
> >
> > Any help would be gratefully appreciated.
> >
> > Thanks,
> > Tony

>
> Try:
>
> Sheets("oSheet").Columns("A:A").ColumnWidth = 5.75
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      16th Jan 2008
oSheet.Columns("A:A").ColumnWidth = 5.75

or

oSheet.Range("A1").Entirecolumn.ColumnWidth = 5.75

Tony Girgenti wrote:
>
> Hello GTVT06.
>
> I'm getting Subscript out of range when i try your code.
>
> Thanks,
> Tony
>
> "GTVT06" wrote:
>
> > On Jan 15, 8:21 pm, Tony Girgenti <tony(nospam)@lakesideos.com> wrote:
> > > Hello.
> > >
> > > Using VB6.0 and Excel 2002. I'm trying to change the column width of a
> > > column before saving the workbook. I can do other changes to the worksheet,
> > > like fonts and values etc., but it won't change the columnwidth.
> > >
> > > I tried these statements and none of them work:
> > > oSheet.Range("A1").Columns.ColumnWidth = 5.75
> > > oSheet.Range("A1").ColumnWidth = 5.75
> > > oSheet.Columns("A:A").ColumnWidth = 5.75
> > >
> > > oSheet.Columns("A").Select
> > > Selection.ColumnWidth = 5.75
> > >
> > > Does anybody know how to do this?
> > >
> > > Any help would be gratefully appreciated.
> > >
> > > Thanks,
> > > Tony

> >
> > Try:
> >
> > Sheets("oSheet").Columns("A:A").ColumnWidth = 5.75
> >


--

Dave Peterson
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      16th Jan 2008
What exactly do you have the variable osheet equal to?
Better yet, is it a variable or a sheet name?

"Tony Girgenti" wrote:

> Hello GTVT06.
>
> I'm getting Subscript out of range when i try your code.
>
> Thanks,
> Tony
>
> "GTVT06" wrote:
>
> > On Jan 15, 8:21 pm, Tony Girgenti <tony(nospam)@lakesideos.com> wrote:
> > > Hello.
> > >
> > > Using VB6.0 and Excel 2002. I'm trying to change the column width of a
> > > column before saving the workbook. I can do other changes to the worksheet,
> > > like fonts and values etc., but it won't change the columnwidth.
> > >
> > > I tried these statements and none of them work:
> > > oSheet.Range("A1").Columns.ColumnWidth = 5.75
> > > oSheet.Range("A1").ColumnWidth = 5.75
> > > oSheet.Columns("A:A").ColumnWidth = 5.75
> > >
> > > oSheet.Columns("A").Select
> > > Selection.ColumnWidth = 5.75
> > >
> > > Does anybody know how to do this?
> > >
> > > Any help would be gratefully appreciated.
> > >
> > > Thanks,
> > > Tony

> >
> > Try:
> >
> > Sheets("oSheet").Columns("A:A").ColumnWidth = 5.75
> >

 
Reply With Quote
 
kounoike
Guest
Posts: n/a
 
      16th Jan 2008
i tested below in VB6.0 and Excel2003. it could change the column width of a
column, and almost your code also could change the width of column.

Sub testVB6()
Dim oApp As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Set oApp = New Excel.Application

oApp.Visible = True
On Error Resume Next
Set oBook = oApp.Workbooks.Open("C:\testsample.xls")
If oBook Is Nothing Then
Set oBook = oApp.Workbooks.Add
oBook.SaveAs "C:\testsample.xls"
End If

Set oSheet = oBook.Worksheets(1)
oSheet.Columns("A").ColumnWidth = 5.75
oSheet.Range("A1") = oSheet.Columns("A").ColumnWidth

oApp.DisplayAlerts = False
oBook.Close SaveChanges:=True
Set oSheet = Nothing
Set oBook = Nothing
oApp.Quit
Set oApp = Nothing
End Sub

keiji

"Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
news:E66D4BEE-0AD3-4E51-BB2F-(E-Mail Removed)...
> Hello.
>
> Using VB6.0 and Excel 2002. I'm trying to change the column width of a
> column before saving the workbook. I can do other changes to the
> worksheet,
> like fonts and values etc., but it won't change the columnwidth.
>
> I tried these statements and none of them work:
> oSheet.Range("A1").Columns.ColumnWidth = 5.75
> oSheet.Range("A1").ColumnWidth = 5.75
> oSheet.Columns("A:A").ColumnWidth = 5.75
>
> oSheet.Columns("A").Select
> Selection.ColumnWidth = 5.75
>
> Does anybody know how to do this?
>
> Any help would be gratefully appreciated.
>
> Thanks,
> Tony


 
Reply With Quote
 
Tony Girgenti
Guest
Posts: n/a
 
      19th Jan 2008
Hello JLGWhiz.

I used the code posted by kounoike in this thread. It works fine except
that it doesn't change the column width. I makes all of the other changes as
far as values and fonts, etc., but not the column width.

Can this really be done?

Thanks,
Tony

"JLGWhiz" wrote:

> What exactly do you have the variable osheet equal to?
> Better yet, is it a variable or a sheet name?
>
> "Tony Girgenti" wrote:
>
> > Hello GTVT06.
> >
> > I'm getting Subscript out of range when i try your code.
> >
> > Thanks,
> > Tony
> >
> > "GTVT06" wrote:
> >
> > > On Jan 15, 8:21 pm, Tony Girgenti <tony(nospam)@lakesideos.com> wrote:
> > > > Hello.
> > > >
> > > > Using VB6.0 and Excel 2002. I'm trying to change the column width of a
> > > > column before saving the workbook. I can do other changes to the worksheet,
> > > > like fonts and values etc., but it won't change the columnwidth.
> > > >
> > > > I tried these statements and none of them work:
> > > > oSheet.Range("A1").Columns.ColumnWidth = 5.75
> > > > oSheet.Range("A1").ColumnWidth = 5.75
> > > > oSheet.Columns("A:A").ColumnWidth = 5.75
> > > >
> > > > oSheet.Columns("A").Select
> > > > Selection.ColumnWidth = 5.75
> > > >
> > > > Does anybody know how to do this?
> > > >
> > > > Any help would be gratefully appreciated.
> > > >
> > > > Thanks,
> > > > Tony
> > >
> > > Try:
> > >
> > > Sheets("oSheet").Columns("A:A").ColumnWidth = 5.75
> > >

 
Reply With Quote
 
Tony Girgenti
Guest
Posts: n/a
 
      19th Jan 2008
Hello kounoike.

I tried using your code. It works great except that it put a value in cell
A1 of 5.71 and it did not change the column width to 5.75. It makes all of
the other changes for values and fonts, etc., but not the column width.

Thanks,
Tony

"kounoike" wrote:

> i tested below in VB6.0 and Excel2003. it could change the column width of a
> column, and almost your code also could change the width of column.
>
> Sub testVB6()
> Dim oApp As Excel.Application
> Dim oBook As Excel.Workbook
> Dim oSheet As Excel.Worksheet
> Set oApp = New Excel.Application
>
> oApp.Visible = True
> On Error Resume Next
> Set oBook = oApp.Workbooks.Open("C:\testsample.xls")
> If oBook Is Nothing Then
> Set oBook = oApp.Workbooks.Add
> oBook.SaveAs "C:\testsample.xls"
> End If
>
> Set oSheet = oBook.Worksheets(1)
> oSheet.Columns("A").ColumnWidth = 5.75
> oSheet.Range("A1") = oSheet.Columns("A").ColumnWidth
>
> oApp.DisplayAlerts = False
> oBook.Close SaveChanges:=True
> Set oSheet = Nothing
> Set oBook = Nothing
> oApp.Quit
> Set oApp = Nothing
> End Sub
>
> keiji
>
> "Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
> news:E66D4BEE-0AD3-4E51-BB2F-(E-Mail Removed)...
> > Hello.
> >
> > Using VB6.0 and Excel 2002. I'm trying to change the column width of a
> > column before saving the workbook. I can do other changes to the
> > worksheet,
> > like fonts and values etc., but it won't change the columnwidth.
> >
> > I tried these statements and none of them work:
> > oSheet.Range("A1").Columns.ColumnWidth = 5.75
> > oSheet.Range("A1").ColumnWidth = 5.75
> > oSheet.Columns("A:A").ColumnWidth = 5.75
> >
> > oSheet.Columns("A").Select
> > Selection.ColumnWidth = 5.75
> >
> > Does anybody know how to do this?
> >
> > Any help would be gratefully appreciated.
> >
> > Thanks,
> > Tony

>
>

 
Reply With Quote
 
Tony Girgenti
Guest
Posts: n/a
 
      19th Jan 2008
Hello kounoike.

I used your code and it works fine except that it doesn't change the column
width. I makes all of the other changes as far as values and fonts, etc.,
but not the column width. The value of cell A1 is 5.71 and it's width is
5.71.

Thanks,
Tony


"kounoike" wrote:

> i tested below in VB6.0 and Excel2003. it could change the column width of a
> column, and almost your code also could change the width of column.
>
> Sub testVB6()
> Dim oApp As Excel.Application
> Dim oBook As Excel.Workbook
> Dim oSheet As Excel.Worksheet
> Set oApp = New Excel.Application
>
> oApp.Visible = True
> On Error Resume Next
> Set oBook = oApp.Workbooks.Open("C:\testsample.xls")
> If oBook Is Nothing Then
> Set oBook = oApp.Workbooks.Add
> oBook.SaveAs "C:\testsample.xls"
> End If
>
> Set oSheet = oBook.Worksheets(1)
> oSheet.Columns("A").ColumnWidth = 5.75
> oSheet.Range("A1") = oSheet.Columns("A").ColumnWidth
>
> oApp.DisplayAlerts = False
> oBook.Close SaveChanges:=True
> Set oSheet = Nothing
> Set oBook = Nothing
> oApp.Quit
> Set oApp = Nothing
> End Sub
>
> keiji
>
> "Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
> news:E66D4BEE-0AD3-4E51-BB2F-(E-Mail Removed)...
> > Hello.
> >
> > Using VB6.0 and Excel 2002. I'm trying to change the column width of a
> > column before saving the workbook. I can do other changes to the
> > worksheet,
> > like fonts and values etc., but it won't change the columnwidth.
> >
> > I tried these statements and none of them work:
> > oSheet.Range("A1").Columns.ColumnWidth = 5.75
> > oSheet.Range("A1").ColumnWidth = 5.75
> > oSheet.Columns("A:A").ColumnWidth = 5.75
> >
> > oSheet.Columns("A").Select
> > Selection.ColumnWidth = 5.75
> >
> > Does anybody know how to do this?
> >
> > Any help would be gratefully appreciated.
> >
> > Thanks,
> > Tony

>
>

 
Reply With Quote
 
kounoike
Guest
Posts: n/a
 
      19th Jan 2008
Hi tony

I can change column width in my environment, so i don't have any idea why
you can't change it.
by the way, can you change column width not from VB6 but with Excel VBA?
some code with Excel VBA like this "Columns("A:A").ColumnWidth = 20" could
change the column width of A to 20 on your Excel's activesheet?

keiji

"Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
news:B9AAB911-D987-4744-9D2F-(E-Mail Removed)...
> Hello kounoike.
>
> I used your code and it works fine except that it doesn't change the
> column
> width. I makes all of the other changes as far as values and fonts, etc.,
> but not the column width. The value of cell A1 is 5.71 and it's width is
> 5.71.
>
> Thanks,
> Tony
>
>
> "kounoike" wrote:
>
>> i tested below in VB6.0 and Excel2003. it could change the column width
>> of a
>> column, and almost your code also could change the width of column.
>>
>> Sub testVB6()
>> Dim oApp As Excel.Application
>> Dim oBook As Excel.Workbook
>> Dim oSheet As Excel.Worksheet
>> Set oApp = New Excel.Application
>>
>> oApp.Visible = True
>> On Error Resume Next
>> Set oBook = oApp.Workbooks.Open("C:\testsample.xls")
>> If oBook Is Nothing Then
>> Set oBook = oApp.Workbooks.Add
>> oBook.SaveAs "C:\testsample.xls"
>> End If
>>
>> Set oSheet = oBook.Worksheets(1)
>> oSheet.Columns("A").ColumnWidth = 5.75
>> oSheet.Range("A1") = oSheet.Columns("A").ColumnWidth
>>
>> oApp.DisplayAlerts = False
>> oBook.Close SaveChanges:=True
>> Set oSheet = Nothing
>> Set oBook = Nothing
>> oApp.Quit
>> Set oApp = Nothing
>> End Sub
>>
>> keiji
>>
>> "Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
>> news:E66D4BEE-0AD3-4E51-BB2F-(E-Mail Removed)...
>> > Hello.
>> >
>> > Using VB6.0 and Excel 2002. I'm trying to change the column width of a
>> > column before saving the workbook. I can do other changes to the
>> > worksheet,
>> > like fonts and values etc., but it won't change the columnwidth.
>> >
>> > I tried these statements and none of them work:
>> > oSheet.Range("A1").Columns.ColumnWidth = 5.75
>> > oSheet.Range("A1").ColumnWidth = 5.75
>> > oSheet.Columns("A:A").ColumnWidth = 5.75
>> >
>> > oSheet.Columns("A").Select
>> > Selection.ColumnWidth = 5.75
>> >
>> > Does anybody know how to do this?
>> >
>> > Any help would be gratefully appreciated.
>> >
>> > Thanks,
>> > Tony

>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change the font size of excel row number and column heading =?Utf-8?B?UGF0dHkgQg==?= Microsoft Excel Misc 4 13th Jul 2010 11:35 AM
Excel 2002: How to change default page size for printing? Mr. Low Microsoft Excel Misc 3 22nd Apr 2009 07:01 PM
How do I change cursor size in Word 2002 dude Microsoft Word Document Management 0 7th Feb 2009 03:36 PM
change column size =?Utf-8?B?U2VsYnk=?= Microsoft Access Getting Started 1 17th May 2007 05:55 PM
Excel 2002 files attached to Outlook 2002 EMails change size AJStadlin Microsoft Excel Programming 1 15th Oct 2003 12:12 AM


Features
 

Advertising
 

Newsgroups
 


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