|
I'm 99% sure that the default file format for an Excel 2007 spreadsheet is incompatible with Excel 2003. I also believe that there is a special reader/converter that can be installed on Excel 2003 to read the Excel 2007 formats.
Check this out from Microsoft
http://office.microsoft.com/en-us/excel/HA100141071033.aspx[^]
|
|
|
|
|
No, it's not going to work. You have to develope your code against the lowest version of Office you're going to support. If you wrote it against 2003, it'll still work with 2007.
|
|
|
|
|
Hi,
I have a popup menu items which will be invoked when we right click on a particular file.
My popupmenu
...AddTestCase...OpenFile
...DeleteFile
Now on right click all the three submenus are getting displayed.
But I want AddTestCase menu to be visible only when i rightclick on a HTML file.
Please Help.
Thanks,
Karthick.M
|
|
|
|
|
I take it that you are using a ContextMenuStrip to build the Popup Menu. I am also unsure where you are right clicking, whether it is a list box, listview, textbox or what, but the ContextMenuStrip has an Opening event which fires when opening (really ). You can use this event to check whether the filename ends with ".html" and then use the ContextMenu Items Visible property to display or hide the Item. I did a test with a label like so :
Private Sub ContextMenuStrip1_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)Handles ContextMenuStrip1.Opening
If Label1.Text Like "*.html" Then
ContextMenuStrip1.Items(2).Visible = True
Else
ContextMenuStrip1.Items(2).Visible = False
End If
End Sub
and it works fine.
|
|
|
|
|
Thank you It Worked.
|
|
|
|
|
|
I've been using VB.Net since its release, and I only now learn that there is a Like operator. The things I learn here.
Added: Looking for more info, I find that Like has been around since at least VB6. Crimeny, this would have been useful to know!
|
|
|
|
|
Hello,
I need your help.
I would like to handle two Excel books with VB.net.
Here is a part of my code:
Dim ExcelApp As Object
Dim ExcelBook As Object
Dim ExcelSheet As Object
ExcelApp = New Excel.Application
ExcelApp.Visible = True
ExcelBook = ExcelApp.Workbooks.Open(Folder & "List2")
ExcelBook = ExcelApp.Workbooks.Open(Folder & "List1")
ExcelApp.Workbooks("List1.xlsx").Activate
'Add data to cells of the first workbook
ExcelSheet = ExcelBook.Worksheets(1)
ExcelSheet.Range("A1").Value = "Book 1"
ExcelSheet.Range("B1").Value = "First Name"
ExcelSheet.Range("A1:B1").Font.Bold = True
ExcelSheet.Range("A2").Value = "Max"
ExcelSheet.Range("B2").Value = "Paul"
ExcelApp.Workbooks("List2.xlsx").Activate ' doe not work
'Add data to cells of the second workbook
ExcelSheet = ExcelBook.Worksheets(1)
ExcelSheet.Range("A1").Value = "Book 2"
ExcelSheet.Range("B1").Value = "First Name"
ExcelSheet.Range("A1:B1").Font.Bold = True
ExcelSheet.Range("A2").Value = "Egon"
ExcelSheet.Range("B2").Value = "Franz"
How can I set "List2.xlsx" active to read and write in List2.xlsx and switch back to "List1.xlsx"
The code to activate List2 does not work.
Thanks in advance
Stephan
|
|
|
|
|
I don't do Office Interop, so this may seem like a stupid question.
Why do you even need to call .Activate? All you're doing is setting cell values. You don't have to have the sheet as the "active" sheet to do that. Activate does not turn a sheet from "ReadOnly" to "ReadWrite". All it does is make it the currently viewed sheet, just like you clicked its tab at the bottom of the Excel window.
If you're trying to show a specific sheet to the user, then try following up the call to Workbook.Activate with a Worksheet.Activate that's in that workbook.
|
|
|
|
|
What I will do is to open two or more Excel files with VB.net.
After that I will start to search an value in the first Excel sheet.
If I don't find the value I start the seach again in the next sheet.
The question for me is, how can I chance to different workbooks in the Excel application with VB.net via Office Interop.
Do you have a pice sample code how I can do that.
|
|
|
|
|
stephan0607 wrote: how can I chance to different workbooks in the Excel
If you're asking how you can CHANGE to a different workbook, you already did it in your code. There's a Workbooks collection in the Excel object. In each Workbook object, there is a Worksheets collection.
stephan0607 wrote: Do you have a pice sample code how I can do that
I already said I don't do Office Interop. I'm going entirely on the documentation for the Excel object model.
|
|
|
|
|
How can i change background color of msgbox using vb dot net or vb6. i do not want to use form for this purpose.
|
|
|
|
|
You can't. You have to build a custom form for this.
|
|
|
|
|
but it changes when we change theam in windows xp
|
|
|
|
|
Yes theam Change it. And Theam change all the color style of all over windows.Not only for your application.
so if you want to change Messagebox Color you should to create your custom Form (Messagebox).If you can think then I Can.
|
|
|
|
|
Yeah, because the MessageBox is rendered by the system and uses the system's theme.
|
|
|
|
|
Hi,
I am using VB.NET1.1 and office 2003. I have created a object of Word document, opening it, writing some data into the document Printing it and finally closing the document. However it is throwing this exception while closing the document.
<b>exception from hresult 0x800A140C</b> Here is the code piece:
If (IsNothing(appWord) = True) Then
appWord = ModWord.GetWordApplication
End If
docProposal = ModWord.GetDocument(appWord, lstrFileName)
lstrFileName = docProposal.FullName
lstrFile = docProposal.Name
If (docProposal.MailMerge.Fields.Count > 0) Then
For Each bk As Word.MailMergeField In docProposal.MailMerge.Fields
bk.Locked = True
Next
' Create a data source containing the field data.
docProposal.MailMerge.CreateDataSource(Name:=lstrDataFile, HeaderRecord:="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37")
' Open the file to insert data.
'docProposalData = appWord.Documents.Add(lstrDataFile, Visible:=False)
docProposalData = appWord.Documents.Open(lstrDataFile, Visible:=False)
With docProposalData.Tables.Item(1)
lint = 1
For Each lstr In laHdg
.Cell(1, lint).Range.Text = lstr
lint += 1
Next
lint = 1
For Each lstr In laData
.Cell(2, lint).Range.Text = lstr
lint += 1
Next
End With
' Save and close the data file.
docProposalData.SaveAs(lstrDataFile)
Application.DoEvents()
'The code is breaking at this line.
<b>docProposalData.Close(Word.WdSaveOptions.wdDoNotSaveChanges, , False)
Application.DoEvents()</b>
Please help
For Reference here is GetDocument function
Public Shared Function GetDocument(ByVal wordApplication As Word.Application, ByVal filename As String) As Word.Document
If wordApplication Is Nothing Then
Throw New ApplicationException("Word application is nothing.")
End If
Dim docProposal As Word.Document = wordApplication.Documents.Open(filename)
If filename.EndsWith(".dot") Then
For Each template As Word.Template In wordApplication.Templates
If filename.EndsWith(template.Name) Then
template.Saved = True
End If
Next
filename = filename.Substring(0, filename.IndexOf(".dot")) & ".doc"
docProposal.SaveAs(filename)
End If
Return docProposal
End Function
Thanks & Regards
Puneet
|
|
|
|
|
Hi friends,
I wrote this code to display graphical text on form as well in label control but it has two problems.
1. It display the graphical text on form when I move mouse on a button on the form.
2. It dosnt show anything in label
Pls help.
<code>
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.IO
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
'Create a Graphics object
Dim g As Graphics = Me.CreateGraphics()
'Create font families
Dim verdanaFamily As New FontFamily("Verdana")
Dim arialFamily As New FontFamily("Arial")
AddHandler Label1.Paint, AddressOf Me.Label1_Paint
'Construct font objects
Dim verdanaFont As New Font("Verdana", 10)
Dim arialFont As New Font(arialFamily, 16, FontStyle.Bold)
Dim tahomaFont As New Font("Tahoma", 24, FontStyle.Underline Or FontStyle.Italic)
'Create Brush and other objects
Dim pointF As New PointF(30, 10)
Dim solidBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
'Draw text using DrawString
g.DrawString(TextBox1.Text, verdanaFont, New SolidBrush(Color.Red), New PointF(20, 20))
g.DrawString(TextBox1.Text, arialFont, New SolidBrush(Color.Blue), New PointF(20, 50))
'Dispose of objects
SolidBrush.Dispose()
g.Dispose()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
e.KeyChar = ChrW(AscW(CommonFunctions.AsciiToUnicode(AscW(e.KeyChar))))
End Sub
Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
'Create a Graphics object
Dim g As Graphics = Label1.CreateGraphics
'Create font families
'Construct font objects
Dim tahomaFont As New Font("Tahoma", 24, FontStyle.Underline Or FontStyle.Italic)
'Create Brush and other objects
Dim pointF As New PointF(30, 10)
Dim solidBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
g.DrawString(TextBox1.Text, tahomaFont, New SolidBrush(Color.Green), Label1.Location.X, Label1.Location.Y)
'Dispose of objects
solidBrush.Dispose()
g.Dispose()
End Sub
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
Dim fnt As New Font("Verdana", 16)
Dim g As Graphics = pe.Graphics
g.DrawString(TextBox1.Text, fnt, New SolidBrush(Color.Red), 14, 10)
End Sub 'OnPaint
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Refresh()
End Sub
End Class
</code>
|
|
|
|
|
Why don't you show us the code you wrote and where you are receiving the errors, then we migth be able to help you.
|
|
|
|
|
Your code is messed up to say the least. You can start by removing every line that says "CreateGraphics" and replace it with this:
Dim g As Graphics = e.Graphics
Use the Graphics object passed to you in the event args. Do NOT create your own Graphics object when handling Paint events.
Get rid of your OnPaint method.
You're creating objects all over the place, but only Diposing of some of them. Your code leaks resources like mad because your creating these objects on every Paint event call, but never releasing them. You'll eventually run the system out of resources and Windows will start behaving very strangely. Create objects that do not change over time, like brushes, pens, and fonts, once, and reuse them. Dispose of them when you app closes.
|
|
|
|
|
When I used this code
<pre>Dim g As Graphics = e.Graphics</pre>
Its gives me error at run time that:
Parameter is not valid
|
|
|
|
|
Where are you putting the code? You need to put that code in a Paint event or any function that has a PaintEventArgs Parameter. If you start a new project and put this in the Form1_Paint event like this
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
g.DrawString("Hello, World !", New Font("Verdana", 15), New SolidBrush(Color.Red), New PointF(20, 20))
g.DrawString("This is an example of using a Paint event", New Font("Arial", 12), New SolidBrush(Color.Blue), New PointF(20, 50))
g.Dispose()
End Sub
you shouldn't have any problems.
|
|
|
|
|
Dear Following is my code and below that is the error I get:
<pre>Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.IO
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
g.DrawString(TextBox1.Text, New Font("Verdana", 15), New SolidBrush(Color.Red), New PointF(20, 20))
g.DrawString(TextBox1.Text, New Font("Arial", 12), New SolidBrush(Color.Blue), New PointF(20, 50))
g.Dispose()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
e.KeyChar = ChrW(AscW(CommonFunctions.AsciiToUnicode(AscW(e.KeyChar))))
End Sub
Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
Dim g As Graphics = e.Graphics
g.DrawString(TextBox1.Text, New Font("Verdana", 15), New SolidBrush(Color.Red), New PointF(20, 20))
g.Dispose()
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Refresh()
End Sub
End Class</pre>
<b>Error I get</b>
<
System.ArgumentException was unhandled
Message="Parameter is not valid."
Source="System.Drawing"
StackTrace:
at System.Drawing.Graphics.GetHdc()
at System.Drawing.BufferedGraphics.RenderInternal(HandleRef refTargetDC, BufferedGraphics buffer)
at System.Drawing.BufferedGraphics.Render()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Label.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at DrawStringMethodGDI_.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
>
|
|
|
|
|
I still cannot see what you are trying to do, nor do I know where in the program you are getting the error. Is it when the form is loading, when you type in the textbox , where? Have you made sure that you have put text in the textbox before the form is loaded? Comment out the label_paint, and textbox_keypress events and try running it again. Did you try my example I gave you with strings instead of TextBox1.Text, and what results did that give you ?
|
|
|
|
|
ok I found out the problem that it gives error bcoz of the g.dispose() in the label's paint sub.
but its not showing anything in label
|
|
|
|
|