Few questions about VB Express/excel...

Hello,

How do i make form1.vb and form2.vb share a variable?

I put the variables in the top in the public declarations section but its still only available to the form it is in.. how do i make it available to all forms?

Also slightly unrelated.. can i make excel sheets formating apply to new sheets that are created?

so.. if the text in A1 on sheet1 is red, when i click new sheet i want the text in a1 on sheet2 to also be red.. i have my program working with excel and creating new sheets but once the sheet is created it loses the formating, or if you have an example of how to edit/format cells in VB Express i will just work it into my program however atm i do not know how to manipulate the cells format with VB Express.

Hope you can help, thanks!

[791 byte] By [GazCoder] at [2007-12-23]
# 1

Several ways:

1. Make the variable public in the form (ideally, it would be a property rather than public). Access it through the instance of the form (e.g. Form1.MyVariable)

2. Create a module with a public variable. Access it directly, or through the module.

3. Create a class with a shared variable (again, ideally a public property). Access it through the class name e.g. MyClass.MyVariable.

SJWhiteley at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

Thanks for the reply,

Do you have a code example of this? (im pretty rubbish)

Thanks!

p.s i solved the excel problem, if anyone wants to know here it is...

(in excel)

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Sheet1.Cells.Copy
Sh.Cells.PasteSpecial xlFormats

End Sub

GazCoder at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

Doesn't matter, I got it now :D

Thanks

GazCoder at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...