| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual Basic 6.0 Programming Ask questions about VB 6.0 (or earlier versions) or help others by answering their question. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
[RESOLVED] Changing Font of Excel Cell value Using vb code
can anybody tell me .How should i change the font of the Particular Cell Value.Kindly let me know
the idea.Any help would be highly appreciated.i simple want ExlSheet.Cells(2, 1).Value should be in Bold.But all the text comming in Regular Format.Kindly let me know the idea. Code:
Private Sub btPrint_Click()
Dim excl As Excel.Application
Dim wBook As Excel.Workbook
Dim ExlSheet As Excel.Worksheet
Dim m_SCompanyName As String
m_SCompanyName = "AL ARABI FACTORY FOR STEEL WORKS "
Set excl = New Excel.Application
' Set excl = CreateObject(Excel.Application)
Set wBook = excl.Workbooks.Add
Set ExlSheet = wBook.Worksheets(1)
excl.Visible = True
ExlSheet.Cells(2, 1).Value = m_SCompanyName
ExlSheet.Cells(3, 1).Value = "P.O. BOX 14044 DAMMAM 31424 "
ExlSheet.Cells(4, 1).Value = "KINGDOM OF SAUDI ARABIA "
ExlSheet.Cells(5, 1).Value = "PHONE : (+9663) 812-3070 "
ExlSheet.Cells(6, 1).Value = "FAX : (+9663) 812-3339 "
Set excl = Nothing
End Sub
|
|
#2
|
||||
|
||||
|
Re: Changing Font of Excel Cell value Using vb code
Simple :
Code:
Option Explicit
Private Sub btPrint_Click()
Dim excl As Excel.Application
Dim wBook As Excel.Workbook
Dim ExlSheet As Excel.Worksheet
Dim m_SCompanyName As String
m_SCompanyName = "AL ARABI FACTORY FOR STEEL WORKS "
Set excl = New Excel.Application
' Set excl = CreateObject(Excel.Application)
Set wBook = excl.Workbooks.Add
Set ExlSheet = wBook.Worksheets(1)
excl.Visible = True
ExlSheet.Cells(2, 1).Value = m_SCompanyName
ExlSheet.Cells(3, 1).Value = "P.O. BOX 14044 DAMMAM 31424 "
ExlSheet.Cells(4, 1).Value = "KINGDOM OF SAUDI ARABIA "
ExlSheet.Cells(5, 1).Value = "PHONE : (+9663) 812-3070 "
ExlSheet.Cells(6, 1).Value = "FAX : (+9663) 812-3339 "
ExlSheet.Range("A2").Font.Bold = True 'Only Cell A2 Bold
ExlSheet.Range("A3:A5").Font.Italic = True 'A3 To A5 Italics
ExlSheet.Range("A6, A2").Font.Underline = True 'A2 and A6 Underline
Set excl = Nothing
End Sub
__________________
My Latest Articles : VB and Internet Explorer Browsing History || The TaskBar and VB.NET || Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 Find All My Articles : Here FAQs : .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1 Read This Before You Post || Acceptable Use Policy
Last edited by HanneSThEGreaT; November 4th, 2009 at 07:49 AM. |
|
#3
|
|||
|
|||
|
Can you tell me .How should i insert the the logo means *.jpeg/Gif file in excelsheet.Here is the
Following Code .What i have written.Kindly let me know the idea. Code:
Private Sub btPrint_Click()
Dim excl As Excel.Application
Dim wBook As Excel.Workbook
Dim ExlSheet As Excel.Worksheet
Dim m_SCompanyName As String
m_SCompanyName = "AL ARABI FACTORY FOR STEEL WORKS "
Set excl = New Excel.Application
' Set excl = CreateObject(Excel.Application)
Set wBook = excl.Workbooks.Add
Set ExlSheet = wBook.Worksheets(1)
excl.Visible = True
ExlSheet.Cells(2, 1).Value = m_SCompanyName
ExlSheet.Cells(3, 1).Value = "P.O. BOX 14044 DAMMAM 31424 "
ExlSheet.Cells(4, 1).Value = "KINGDOM OF SAUDI ARABIA "
ExlSheet.Cells(5, 1).Value = "PHONE : (+9663) 812-3070 "
ExlSheet.Cells(6, 1).Value = "FAX : (+9663) 812-3339 "
ExlSheet.Range("A1:A2").Font.Bold = True
Set ExlSheet = Nothing
Set wBook = Nothing
Set excl = Nothing
End Sub
|
|
#4
|
||||
|
||||
|
Re: Changing Font of Excel Cell value Using vb code
You could use :
Code:
ActiveSheet.Pictures.Insert(FileName) Code:
Option Explicit
Sub AddPicture(FileName As String, Target As Range)
Dim Pic As Object, PicTop As Double, PicLeft As Double, PicWidth As Double, PicHeight As Double
'Determine If We Are On A WorkSheet
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
'If Picture Source Doesn't Exist
If Dir(FileName) = "" Then Exit Sub
'Get Picture
Set Pic = ActiveSheet.Pictures.Insert(FileName)
' Get Positions
With Target
PicTop = .Top
PicLeft = .Left
PicWidth = .Offset(0, .Columns.Count).Left - .Left
PicHeight = .Offset(.Rows.Count, 0).Top - .Top
End With
' Place Picture
With Pic
.Top = PicTop
.Left = PicLeft
.Width = PicWidth
.Height = PicHeight
End With
'Release Memory
Set Pic = Nothing
End Sub
Sub PlaceMyPicture()
'Get Picture And Place It In B5:B10
AddPicture "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg", _
Range("B5:D10")
End Sub
Private Sub btPrint_Click()
Dim excl As Excel.Application
Dim wBook As Excel.Workbook
Dim ExlSheet As Excel.Worksheet
Dim m_SCompanyName As String
m_SCompanyName = "AL ARABI FACTORY FOR STEEL WORKS "
Set excl = New Excel.Application
Set wBook = excl.Workbooks.Add
Set ExlSheet = wBook.Worksheets(1)
excl.Visible = True
ExlSheet.Cells(2, 1).Value = m_SCompanyName
ExlSheet.Cells(3, 1).Value = "P.O. BOX 14044 DAMMAM 31424 "
ExlSheet.Cells(4, 1).Value = "KINGDOM OF SAUDI ARABIA "
ExlSheet.Cells(5, 1).Value = "PHONE : (+9663) 812-3070 "
ExlSheet.Cells(6, 1).Value = "FAX : (+9663) 812-3339 "
ExlSheet.Range("A1:A2").Font.Bold = True 'Only Cell A1 & Cell A2 Bold
PlaceMyPicture
Set ExlSheet = Nothing
Set wBook = Nothing
Set excl = Nothing
End Sub
__________________
My Latest Articles : VB and Internet Explorer Browsing History || The TaskBar and VB.NET || Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 Find All My Articles : Here FAQs : .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1 Read This Before You Post || Acceptable Use Policy
|
|
#5
|
|||
|
|||
|
Still Not Working .i am getting errror Insert Method of Pictures Class is failed .Kindly let me know
the idea.Any help would be highly appreciated.here is the following Code .What i have written. Code:
Private Sub btPrint_Click()
Dim excl As Excel.Application
Dim wBook As Excel.Workbook
Dim ExlSheet As Excel.Worksheet
Dim m_SCompanyName As String
m_SCompanyName = "AL ARABI FACTORY FOR STEEL WORKS "
Set excl = New Excel.Application
' Set excl = CreateObject(Excel.Application)
Set wBook = excl.Workbooks.Add
Set ExlSheet = wBook.Worksheets(1)
excl.Visible = True
ExlSheet.Cells(2, 1).Value = m_SCompanyName
ExlSheet.Cells(3, 1).Value = "P.O. BOX 14044 DAMMAM 31424 "
ExlSheet.Cells(4, 1).Value = "KINGDOM OF SAUDI ARABIA "
ExlSheet.Cells(5, 1).Value = "PHONE : (+9663) 812-3070 "
ExlSheet.Cells(6, 1).Value = "FAX : (+9663) 812-3339 "
ExlSheet.Range("A1:A2").Font.Bold = True
ExlSheet.Range("A1:A2").Font.Italic = True
ExlSheet.Range("A1:A5").Font.Underline = True
ActiveSheet.Pictures.Insert (App.path & "FirmSignation.jpg")
Set ExlSheet = Nothing
Set wBook = Nothing
Set excl = Nothing
End Sub
|
|
#6
|
||||
|
||||
|
Re: Changing Font of Excel Cell value Using vb code
Mine Works....
__________________
My Latest Articles : VB and Internet Explorer Browsing History || The TaskBar and VB.NET || Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 Find All My Articles : Here FAQs : .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1 Read This Before You Post || Acceptable Use Policy
|
|
#7
|
|||
|
|||
|
But i am getting Type Mismatch Error .Here is the following Code what i have written.Kindly let me
Know the idea. Code:
Public Sub PlacePicture()
AddPicture App.path & "\FirmSignation.jpg", _
Range("B5:D10")
End Sub
Private Sub btPrint_Click()
Dim excl As Excel.Application
Dim wBook As Excel.Workbook
Dim ExlSheet As Excel.Worksheet
Dim m_SCompanyName As String
m_SCompanyName = "AL ARABI FACTORY FOR STEEL WORKS "
Set excl = New Excel.Application
Set wBook = excl.Workbooks.Add
Set ExlSheet = wBook.Worksheets(1)
excl.Visible = True
ExlSheet.Cells(2, 1).Value = m_SCompanyName
ExlSheet.Cells(3, 1).Value = "P.O. BOX 14044 DAMMAM 31424 "
ExlSheet.Cells(4, 1).Value = "KINGDOM OF SAUDI ARABIA "
ExlSheet.Cells(5, 1).Value = "PHONE : (+9663) 812-3070 "
ExlSheet.Cells(6, 1).Value = "FAX : (+9663) 812-3339 "
ExlSheet.Range("A1:A2").Font.Bold = True 'Only Cell A1 & Cell A2 Bold
PlaceMyPicture
Set ExlSheet = Nothing
Set wBook = Nothing
Set excl = Nothing
End Sub
Sub AddPicture(FileName As String, Target As Range)
Dim Pic As Object, PicTop As Double, PicLeft As Double, PicWidth As Double, PicHeight As Double
'Determine If We Are On A WorkSheet
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
'If Picture Source Doesn't Exist
If Dir(FileName) = "" Then Exit Sub
'Get Picture
Set Pic = ActiveSheet.Pictures.Insert(FileName)
' Get Positions
With Target
PicTop = .Top
PicLeft = .Left
PicWidth = .Offset(0, .Columns.Count).Left - .Left
PicHeight = .Offset(.Rows.Count, 0).Top - .Top
End With
' Place Picture
With Pic
.Top = PicTop
.Left = PicLeft
.Width = PicWidth
.Height = PicHeight
End With
'Release Memory
Set Pic = Nothing
End Sub
Code:
Public Sub PlacePicture()
AddPicture App.path & "\FirmSignation.jpg", _
Range("B5:D10")
End Sub
|
|
#8
|
||||
|
||||
|
Re: Changing Font of Excel Cell value Using vb code
What version of Excel are you using ¿
__________________
My Latest Articles : VB and Internet Explorer Browsing History || The TaskBar and VB.NET || Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 Find All My Articles : Here FAQs : .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1 Read This Before You Post || Acceptable Use Policy
|
|
#9
|
|||
|
|||
|
i am Using Excel 2003.Kindly let me know the idea.
|
|
#10
|
||||
|
||||
|
Re: Changing Font of Excel Cell value Using vb code
Then, honestly, frankly, I am clueless as to what your problem is
![]() My version works in Excel 2003. Suggestion : Add your VB Project here, in Zip Format, and add your picture here as well. We could then have a look and possibly suggest further.
__________________
My Latest Articles : VB and Internet Explorer Browsing History || The TaskBar and VB.NET || Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 Find All My Articles : Here FAQs : .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1 Read This Before You Post || Acceptable Use Policy
|
|
#11
|
|||
|
|||
|
Thank You very much .Now it is Working .here is the following code what i have written.
Code:
Private Sub btPrint_Click()
Dim excl As Excel.Application
Dim wBook As Excel.Workbook
Dim ExlSheet As Excel.Worksheet
Dim m_SCompanyName As String
m_SCompanyName = "AL ARABI FACTORY FOR STEEL WORKS "
Set excl = New Excel.Application
' Set excl = CreateObject(Excel.Application)
Set wBook = excl.Workbooks.Add
Set ExlSheet = wBook.Worksheets(1)
excl.Visible = True
ExlSheet.Cells(2, 1).Value = m_SCompanyName
ExlSheet.Cells(3, 1).Value = "P.O. BOX 14044 DAMMAM 31424 "
ExlSheet.Cells(4, 1).Value = "KINGDOM OF SAUDI ARABIA "
ExlSheet.Cells(5, 1).Value = "PHONE : (+9663) 812-3070 "
ExlSheet.Cells(6, 1).Value = "FAX : (+9663) 812-3339 "
ExlSheet.Range("A1:A2").Font.Bold = True
ExlSheet.Range("A1:A2").Font.Italic = True
ExlSheet.Range("A1:A5").Font.Underline = True
' ActiveSheet.Pictures.Insert (App.path & "FirmSignation.jpg"), Range("B5:D10")
' Call PlacePicture
wBook.SaveAs App.path & "PurchaseOrder.Xls"
' wBook.Close savechanges:=True
Set ExlSheet = Nothing
Set wBook = Nothing
' excl.Quit
Set excl = Nothing
End Sub
Public Sub PlacePicture()
AddPicture App.path & "\FirmSignation.jpg", _
Range("B5:D10")
End Sub
Sub AddPicture(FileName As String, Target As Range)
Dim Pic As Object, PicTop As Double, PicLeft As Double, PicWidth As Double, PicHeight As Double
'Determine If We Are On A WorkSheet
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
'If Picture Source Doesn't Exist
If Dir(FileName) = "" Then Exit Sub
'Get Picture
Set Pic = ActiveSheet.Pictures.Insert(FileName)
' Get Positions
With Target
PicTop = .Top
PicLeft = .Left
PicWidth = .Offset(0, .Columns.Count).Left - .Left
PicHeight = .Offset(.Rows.Count, 0).Top - .Top
End With
' Place Picture
With Pic
.Top = PicTop
.Left = PicLeft
.Width = PicWidth
.Height = PicHeight
End With
'Release Memory
Set Pic = Nothing
End Sub
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|