Problems with Selection
I have a macro which populate a worsheet from AutoCAD thru automation. It
worked fine before upgrading to Office 2007. Now it is almost always failing when I use the selection object to format the cells, for example WSheet.Range("A1:" & Col & "1").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Font.Name = "Arial" .Font.FontStyle = "Bold" .Font.Size = 10 End With some times this code works and other times fails. I can't find information about the selection object. Can someone suggest a better way of doing this? Thanks. |
Problems with Selection
Your code ran fine multiple times for me in Excel 2007.
Fwiw, selecting is usually an unnecessary step, although I don't know if skipping it will help in your case: With WSheet.Range("A1:" & Col & "1") .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Font.Name = "Arial" .Font.FontStyle = "Bold" .Font.Size = 10 End With -- Jim "HLong" wrote in message ... |I have a macro which populate a worsheet from AutoCAD thru automation. It | worked fine before upgrading to Office 2007. Now it is almost always failing | when I use the selection object to format the cells, for example | | WSheet.Range("A1:" & Col & "1").Select | | With Selection | .HorizontalAlignment = xlCenter | .VerticalAlignment = xlCenter | .Font.Name = "Arial" | .Font.FontStyle = "Bold" | .Font.Size = 10 | End With | | some times this code works and other times fails. I can't find information | about the selection object. Can someone suggest a better way of doing this? | Thanks. |
Problems with Selection
Thank you Jim, it seems to be the solution. After I changed the line, it
seems to be working without a glitch. "Jim Rech" wrote: Your code ran fine multiple times for me in Excel 2007. Fwiw, selecting is usually an unnecessary step, although I don't know if skipping it will help in your case: With WSheet.Range("A1:" & Col & "1") .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Font.Name = "Arial" .Font.FontStyle = "Bold" .Font.Size = 10 End With -- Jim "HLong" wrote in message ... |I have a macro which populate a worsheet from AutoCAD thru automation. It | worked fine before upgrading to Office 2007. Now it is almost always failing | when I use the selection object to format the cells, for example | | WSheet.Range("A1:" & Col & "1").Select | | With Selection | .HorizontalAlignment = xlCenter | .VerticalAlignment = xlCenter | .Font.Name = "Arial" | .Font.FontStyle = "Bold" | .Font.Size = 10 | End With | | some times this code works and other times fails. I can't find information | about the selection object. Can someone suggest a better way of doing this? | Thanks. |
All times are GMT +1. The time now is 09:36 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com