Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Some Help Please to Translate an Excel Macro into VB.Net Code

I am building an Excel spreadsheet using VB.Net code. I want the vertical
alignment for all cells to be "Top". To know what code I'd need I turned on
macro recording and went through the manual process. I got the following
result ...

Cells.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

I only care about the vertical alignment, so I am not trying to do any of
the other stuff in VB.Net. Instead of the Cells.Select I found that in my
code I'd need "objSheet.Cells.Select()" - that compiles and builds without
error. It's the vertical alignment line that is causing me problems.
"objSheet.Selection.VerticalAlighment = objApp.xltop" does not work because
Selection is not a member of Excel._Worksheet and
"objSheet.VerticalAlighment = objApp.xltop" does not work because
verticalalignment is not a member of Excel._Worksheet.

I'll appreciate any help anyone can offer. Thanks, Bob


  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Some Help Please to Translate an Excel Macro into VB.Net Code

In Excel VBA, this would normally be done with
objSheet.Cells.VerticalAlignment = xlTop

(I've not worked w/VB.Net so you may need objApp.xlTop as you posted. If
xltop doesn't work, try using -4160 instead).


"eBob.com" wrote:

I am building an Excel spreadsheet using VB.Net code. I want the vertical
alignment for all cells to be "Top". To know what code I'd need I turned on
macro recording and went through the manual process. I got the following
result ...

Cells.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

I only care about the vertical alignment, so I am not trying to do any of
the other stuff in VB.Net. Instead of the Cells.Select I found that in my
code I'd need "objSheet.Cells.Select()" - that compiles and builds without
error. It's the vertical alignment line that is causing me problems.
"objSheet.Selection.VerticalAlighment = objApp.xltop" does not work because
Selection is not a member of Excel._Worksheet and
"objSheet.VerticalAlighment = objApp.xltop" does not work because
verticalalignment is not a member of Excel._Worksheet.

I'll appreciate any help anyone can offer. Thanks, Bob



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Some Help Please to Translate an Excel Macro into VB.Net Code

Thank you JMB. I did have to use -4160; objApp.xlTop compiles and builds OK
but results in a runtime error. Additional thanks for including the hint
about -4160. I would have been spinning my wheels on that one for awhile!

Thanks, Bob

"JMB" wrote in message
...
In Excel VBA, this would normally be done with
objSheet.Cells.VerticalAlignment = xlTop

(I've not worked w/VB.Net so you may need objApp.xlTop as you posted. If
xltop doesn't work, try using -4160 instead).


"eBob.com" wrote:

I am building an Excel spreadsheet using VB.Net code. I want the
vertical
alignment for all cells to be "Top". To know what code I'd need I turned
on
macro recording and went through the manual process. I got the following
result ...

Cells.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

I only care about the vertical alignment, so I am not trying to do any of
the other stuff in VB.Net. Instead of the Cells.Select I found that in
my
code I'd need "objSheet.Cells.Select()" - that compiles and builds
without
error. It's the vertical alignment line that is causing me problems.
"objSheet.Selection.VerticalAlighment = objApp.xltop" does not work
because
Selection is not a member of Excel._Worksheet and
"objSheet.VerticalAlighment = objApp.xltop" does not work because
verticalalignment is not a member of Excel._Worksheet.

I'll appreciate any help anyone can offer. Thanks, Bob





  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Some Help Please to Translate an Excel Macro into VB.Net Code

Only because I've spun my wheels on that when I first tried to automate Word
w/an Excel macro <g. Come to find out (thanks to Peo) I couldn't use word
constants as I was using late binding instead of early binding (which also
required a reference set to Microsoft Word through Tools/References in the
VBA editor).

At any rate, if you need the underlying value for XL constants, go into the
VBA editor in XL (Alt F11) and enter

?xltop

in the immediate window (Cntrl+G or View/Immediate Window).

Glad to hear you got it working.

"eBob.com" wrote:

Thank you JMB. I did have to use -4160; objApp.xlTop compiles and builds OK
but results in a runtime error. Additional thanks for including the hint
about -4160. I would have been spinning my wheels on that one for awhile!

Thanks, Bob

"JMB" wrote in message
...
In Excel VBA, this would normally be done with
objSheet.Cells.VerticalAlignment = xlTop

(I've not worked w/VB.Net so you may need objApp.xlTop as you posted. If
xltop doesn't work, try using -4160 instead).


"eBob.com" wrote:

I am building an Excel spreadsheet using VB.Net code. I want the
vertical
alignment for all cells to be "Top". To know what code I'd need I turned
on
macro recording and went through the manual process. I got the following
result ...

Cells.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

I only care about the vertical alignment, so I am not trying to do any of
the other stuff in VB.Net. Instead of the Cells.Select I found that in
my
code I'd need "objSheet.Cells.Select()" - that compiles and builds
without
error. It's the vertical alignment line that is causing me problems.
"objSheet.Selection.VerticalAlighment = objApp.xltop" does not work
because
Selection is not a member of Excel._Worksheet and
"objSheet.VerticalAlighment = objApp.xltop" does not work because
verticalalignment is not a member of Excel._Worksheet.

I'll appreciate any help anyone can offer. Thanks, Bob






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could someone HELP TRANSLATE this simple psuedo code into MACRO pl bxc2739[_3_] Excel Programming 1 April 27th 06 07:46 PM
Could someone HELP TRANSLATE this simple psuedo code into MACRO please?! bxc2739 Excel Discussion (Misc queries) 3 April 27th 06 06:53 PM
translate ws formula to vba code L Scholes Excel Programming 2 April 17th 06 03:34 AM
Macro translate from number to text thanhnguyen[_14_] Excel Programming 1 March 27th 06 05:43 AM
translate lotus 1-2-3 macro into excel macro using excel 2000 krutledge0209 Excel Programming 1 November 2nd 04 05:50 PM


All times are GMT +1. The time now is 09:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"