Connecting Tech Pros Worldwide Forums | Help | Site Map

Excel modify in VB6

Member
 
Join Date: Oct 2007
Location: Australia
Posts: 83
#1: Jan 10 '08
Hi all, I have some code to open an Excel file and I can edit the Excel file easily,

Expand|Select|Wrap|Line Numbers
  1. Dim xlapp As excel.Application
  2. Dim xlbook As excel.WorkBook
  3. Dim xlsheet As excel.WorkSheet
  4.  
  5. Set xlbook = GetObject("d:\TEST.xls")
  6. Set xlapp = xlbook.Parent
  7.  
  8.  
  9. xlapp.Visible = True
  10. xlapp.Windows("TEST.XLS").Visible = True
  11. Set xlsheet = xlbook.Sheets("Sheet1")
  12. xlsheet.Cells(1,1) = "TEXT"
I have some problem with particular case, such as : How i can make Bold of text in the excel sheet, how it is possible to make a table or line,
and change color of text in excel sheet? Thanks a lot 4 your time.

Expert
 
Join Date: Jun 2007
Location: Derbyshire, UK
Posts: 347
#2: Jan 14 '08

re: Excel modify in VB6


Quote:

Originally Posted by shaiful

Hi all, I have some code to open an Excel file and I can edit the Excel file easily,

Expand|Select|Wrap|Line Numbers
  1. Dim xlapp As excel.Application
  2. Dim xlbook As excel.WorkBook
  3. Dim xlsheet As excel.WorkSheet
  4.  
  5. Set xlbook = GetObject("d:\TEST.xls")
  6. Set xlapp = xlbook.Parent
  7.  
  8.  
  9. xlapp.Visible = True
  10. xlapp.Windows("TEST.XLS").Visible = True
  11. Set xlsheet = xlbook.Sheets("Sheet1")
  12. xlsheet.Cells(1,1) = "TEXT"
I have some problem with particular case, such as : How i can make Bold of text in the excel sheet, how it is possible to make a table or line,
and change color of text in excel sheet? Thanks a lot 4 your time.

Hi

You need something like this

xlsheet.Cells(1,1) .Font.ColorIndex = 5 'Blue
xlsheet.Cells(1,1) .Font.Bold = True

Hint; The easiest way to find out Excel syntax is to record macros and adapt the resulting code.


MTB
Newbie
 
Join Date: Nov 2006
Location: Delhi
Posts: 10
#3: Jan 15 '08

re: Excel modify in VB6


Dim xlapp As Excel.Application
Dim xlbook As Excel.WorkBook
Dim xlsheet As Excel.WorkSheet
Set xlbook = GetObject("d:\visual basic\TEST.xls")
Set xlapp = xlbook.Parent
xlapp.Visible = True
xlapp.Windows("TEST.XLS").Visible = True
Set xlsheet = xlbook.Sheets("Sheet1")
xlsheet.Cells(1, 1) = "TEXT"
xlsheet.Cells(1, 1).Font.Bold = True ' Make text bold
xlsheet.Cells(1, 1).Font.ColorIndex = 8 ' Color
xlsheet.Shapes.AddLine(236.25, 217.5, 351#, 291#).Select ' Line




Hope this code will help you.
Reply