E
Ed White
I'm using VSTO (Visual Studio 2008) with Excel 2007. In a spreadsheet in
Excel, I have a couple Data Tables with data imported from SQL Server
(Data->From Other Sources-->From SQL Server). I've written a sub that
Refreshes the data tables, and at the sub, it tries to AutoFit the columns.
Globals.ThisWorkbook.RefreshAll()
Me.Columns("A:BZ").EntireColumn.AutoFit()
My.Computer.Audio.Play(MediaPath & "notify.wav",AudioPlayMode.WaitToComplete)
It needs to resize the columns because one data table is below the other
(i.e. in the same Excel columns), and when the second one refreshes and
resizes its columns, it sometimes makes the columns too narrow for the first
table.
The AutoFit in the code above is ineffective. Actually, it is executed (and
does temporarily change the column widths), but then after the sub finishes,
Excel reformats the spreadsheet, and then the columns are not the correct
size. You can see and hear this when you run the above sub: the data is
Refreshed, the screen columns are adjusted, you hear the notify.wav sound,
and then Excel reformats the spreadsheet.
How can I get the columns to autofit in my VSTO sub?
Excel, I have a couple Data Tables with data imported from SQL Server
(Data->From Other Sources-->From SQL Server). I've written a sub that
Refreshes the data tables, and at the sub, it tries to AutoFit the columns.
Globals.ThisWorkbook.RefreshAll()
Me.Columns("A:BZ").EntireColumn.AutoFit()
My.Computer.Audio.Play(MediaPath & "notify.wav",AudioPlayMode.WaitToComplete)
It needs to resize the columns because one data table is below the other
(i.e. in the same Excel columns), and when the second one refreshes and
resizes its columns, it sometimes makes the columns too narrow for the first
table.
The AutoFit in the code above is ineffective. Actually, it is executed (and
does temporarily change the column widths), but then after the sub finishes,
Excel reformats the spreadsheet, and then the columns are not the correct
size. You can see and hear this when you run the above sub: the data is
Refreshed, the screen columns are adjusted, you hear the notify.wav sound,
and then Excel reformats the spreadsheet.
How can I get the columns to autofit in my VSTO sub?