Results 1 to 2 of 2

Thread: currency from VB

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    manchester, england
    Posts
    84

    currency from VB

    How can a format a cell in Excel to currency from VB?
    I think I have the first bit but I can not figure it out

    Also how do I format column B so that everything in it is centred?

    x1sheet.Cells(10, 2).


    Thanks

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Once you have the file open in VB, create a Range and then do your formating. Also, best way to find out how to do anything in Excel or Word is to record a macro.

    VB Code:
    1. Dim objExcel As Excel.Application
    2.     Dim objWorkSheet As Excel.Worksheet
    3.     Dim r As Excel.Range
    4.  
    5.     ' section opening Excel not included.
    6.  
    7.     ' open the file
    8.     objExcel.Workbooks.Open "C:\my documents\newfile.xls"
    9.    
    10.     ' create reference to sheet3
    11.     Set objWorkSheet = objExcel.Worksheets.Item("sheet3")
    12.    
    13.     ' activate sheet3
    14.     objWorkSheet.Activate
    15.    
    16.      ' make it visible
    17.     objExcel.Visible = True
    18.    
    19.     ' create range object
    20.     Set r = objWorkSheet.Range("B1:B35")
    21.    
    22.     ' set text alignment and Currency
    23.     r.NumberFormat = "$#,##0.00"
    24.     r.HorizontalAlignment = xlRight
    25.     r.VerticalAlignment = xlBottom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width