Work with Excel

Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-07-16 02:01 PM
Hi,
How to work with Excel file? I mean modifying the file,such as adding borders, changing font etc. Are there particular VBOs used for it?
Thanks
P.K.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-07-16 06:28 PM
All,
I'm no expert at VB, but the below should work. For the border actions, you could of course pass in a input for line style and weight and make the decision as to what to apply. But the below just uses a static value.
=================
COLORS
=================
INPUTS
=================
Handle [Number] (e.g. 1)
Workbook[Text] (e.g. ""myspreadsheet.xlsx"")
Worksheet [Text] (e.g. ""sheet1"")
myrange [Text] (e.g. ""A1:F8"")
r [Number] (e.g. 100)
g [Number] (e.g. 100)
b [Number] (e.g. 100)
================
CODE
================
Dim wb, ws As Object
Dim excel, sheet As Object
wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)
wb.Activate()
ws.Activate()
excel = ws.Application
sheet = excel.ActiveSheet
ws.Range(myrange).Interior.Color = RGB(r,g,b)
===========
BORDERS - Around a range (excluding internal borders)
===========
INPUTS
=================
Handle [Number] (e.g. 1)
Workbook[Text] (e.g. ""myspreadsheet.xlsx"")
Worksheet [Text] (e.g. ""sheet1"")
myrange [Text] (e.g. ""A1:F8"")
r [Number] (e.g. 100)
g [Number] (e.g. 100)
b [Number] (e.g. 100)
================
CODE
================
Dim wb, ws As Object
Dim excel, sheet As Object
wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)
wb.Activate()
ws.Activate()
excel = ws.Application
sheet = excel.ActiveSheet
Const xlContinuous = 1
Const xlThick = 4
Const xlSuperThin = 1
Const xlThin = 2
Const xlMedium = 3
ws.Range(myrange).BorderAround(LineStyle:=xlContinuous, Weight:=xlThin, color:=RGB(r,g,b))
===========
BORDERS - Around a range (including internal borders)
===========
INPUTS
=================
Handle [Number] (e.g. 1)
Workbook[Text] (e.g. ""myspreadsheet.xlsx"")
Worksheet [Text] (e.g. ""sheet1"")
myrange [Text] (e.g. ""A1:F8"")
r [Number] (e.g. 100)
g [Number] (e.g. 100)
b [Number] (e.g. 100)
================
CODE
================
Dim wb, ws As Object
Dim excel, sheet As Object
wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)
wb.Activate()
ws.Activate()
excel = ws.Application
sheet = excel.ActiveSheet
Const xlContinuous = 1
Const xlThick = 4
Const xlSuperThin = 1
Const xlThin = 2
Const xlMedium = 3
Dim rng =ws.Range(myrange)
With rng.Borders
.LineStyle = xlContinuous
.Color = RGB(r,g,b)
.Weight = xlThin
End With
