MS Excel: Actions for aligning, bolding and underlining
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
23-05-17 05:18 PM
Hello,
I would need to do some cell formatting in Excel (aligning left+right+center, bolding, underlining) and apparently there is no way to do these with basic Excel VBO actions. Has somebody struggled with same thing and found a way to do these?
I have very little knowledge of VB.NET but I´ve tried to write separate code stages for each of these actions but cannot get those working.
Here´s a code example:
------------------------
Dim wb, excel, range As Object
Try
wb = GetWorkbook(Handle, Nothing).ActiveSheet
excel = wb.Application
range = excel.Selection
range.HorizontalAlignment = xlRight
Finally
End Try
-------------------------------
When I press Check Code I get error "Compiler error - xlRight is not defined". I assume it´s because required assembly and namespace are missing. I added Assembly: Microsoft.Office.Interop.Excel.dll and Namespace: Microsoft.Office.Interop.Excel. After that Check Code does not give error anymore.
However when I try to run the process, it stops to the first step and gives an error:
23.5.2017 9:41:07 ACTION: 'Create instance' Process: 'AR Dunning New' Subsheet: 'Import Excel sheets to collections' ERROR: Internal : Could not run the object because one of the code stages has a compile error, use Check for Errors for a list of problems
Any help would be highly appreciated!
BR, Jari
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
24-05-17 06:01 PM
Thanks a lot Bastiaan! That helped and now the code works.
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
29-05-18 01:06 PM
Hi Jari,
Can you please share what did you do that helped ? I am getting a similar error.
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
29-05-18 01:10 PM
Hi Jari,
Can you please share what did you do that helped ? I am getting a similar error.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
30-05-18 01:38 PM
Hi Jari,
You code for formatting is correct just need to put an numeric value for ""xlRight"".
Please refer below link to get all numeric values
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel…
Hope this resolves your issue.
