Form that selects files and runs VBA code - vb.net

Say I have two Excel files and a VBA code file:
File1.xlsx
File2.xlsx
Macro.vb
Using Visual Basic I am attempting to create a Windows form program that will allow me to Browse for File1, File2 and the Macro file.
Once the files are selected, the macro needs to use data from both File1 and File2 and update File1.
Here is a pic of the form, and the lines of code for it.
Public Class frmStuff
Private Sub btnBrowse1_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse1.Click
End Sub
Private Sub btnBrowse2_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse2.Click
End Sub
Private Sub btnBrowse3_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse3.Click
End Sub
Private Sub txtFile1_Text(sender As System.Object, e As System.EventArgs) Handles txtFile1.Text
End Sub
Private Sub txtFile2_Text(sender As System.Object, e As System.EventArgs) Handles txtFile2.Text
End Sub
Private Sub txtMacro_Text(sender As System.Object, e As System.EventArgs) Handles txtMacro.Text
End Sub
Private Sub btnRun_Click(sender As System.Object, e As System.EventArgs) Handles btnRun.Click
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
End Sub
End Class
Do the Excel files need to be open for the macro to run?
If they do could I also please have help on opening the Excel files.

Sorry, was being a little impulsive. I have since worked on this and have got it working to a certain point.
The issues that I am now having and will post if I can not resolve myself.
Cheers anyway

Related

how do i save time in datagridview in vb.net 2010 [Newbie student]

Example i press start time and the time connected in textbox that it will show when i start the time same with out time,and when i press save it wont add to datagridview. Please help me with my problem. This is my save code:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Table1BindingSource.AddNew()
Me.Validate()
Me.Table1BindingSource.EndEdit()
Me.Table1TableAdapter.Update(Me.OpenDataSet.Table1)
End Sub
Ok, I solved your problem....
Here is how your form should look like :
And now you need to add the "Time" columns to the datagridview:
And now... follow my steps through the image:
and here is the code :
Public Class Form1
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Table1BindingSource.Rows.Add()
Table1BindingSource.Rows(Table1BindingSource.Rows.Count - 1).Cells(0).Value = TextBox1.Text & Table1BindingSource.Rows.Count
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CountTimer.Tick
TextBox1.Text += 1
End Sub
End Class
I Hope My Answer Was Useful To You :)

Insert,update delete in vb.net

I edited my question and heres the whole code i used
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'GradesDBDataSet.tblGrades' table. You can move, or remove it, as needed.
Me.TblGradesTableAdapter.Fill(Me.GradesDBDataSet.tblGrades)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TblGradesBindingSource.MoveNext()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
TblGradesBindingSource.RemoveCurrent()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TblGradesBindingSource.MovePrevious()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TblGradesBindingSource.MoveLast()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TblGradesBindingSource.MoveFirst()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TblGradesBindingSource.AddNew()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
On Error GoTo saveErr
TblGradesBindingSource.EndEdit()
TblGradesTableAdapter.Update(GradesDBDataSet.tblGrades)
MsgBox("Record Save ", MsgBoxStyle.Information)
saveErr:
Exit Sub
End Sub
End Class
Hello Everyone... i have a problem using this code. . to save data to ms access from vb.net
i just follow a tutorial in youtube. it works BUT when i close the program then minutes later I run it again, data doesnt saved. . . Why? .
And can you suggest whats is the best way to Add, DELETE SAVE using vb.net? thanks eveyone ^_^
The most likely answer is that you are using a local data file that is overwritten each time you build.
Read this to learn how local data files are managed:
http://msdn2.microsoft.com/en-us/library/ms246989(VS.80).aspx
The solution in that case is to select the data file in the Solution Explorer, open the Properties window and set the Copy to output directory property to Copy if newer. The source file will only be copied to the output folder if you have changed that source file. That means that you can keep your test data between sessions.

vb.net read txtfile and navigate to that site (own browser development)

I have built my own browser 9see attached code) however I would like to modify the code so that textbox1 reads a txt file at start and uses the contents of that text file to navigate to a URL of equal value to the text with in that text file. All this should happen at the launch of the web browser form.
Example of the text file contents would be http://www.testsite.com
Code as follows:
#Region "Webbrowser navigation"
Private Sub Go()
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Go()
End Sub
Private Sub TextBox1_keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Go()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.GoBack()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Stop()
End Sub
#End Region
how can I best do this?
In the event handler for the form's Load event, do something like this:
TextBox1.Text = File.ReadAllText("StartUrl.txt")
Go()
However, unless you have some good reason to use a text file, I would suggest something more flexible and standard such as XML. If you don't mind using the standard app.config file, just add one of those to your project and you can use the ConfigurationManager class to read the setting.

Manipulating Controls On Parent Forms From Child VB.NET

I'm trying to add a new row to a DataGridView from FORM 2 but I can not succeed, the code I tried is as follows:
FORM 2:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FORM1.invoice_items.Rows.Add()
End Sub
Looking like it took time but can not find a solution, someone who can help me with my problem would be nice, Thank You.
Try this
This work only if you use a showdialog.
Form 2 :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Pass the value to be added in the datagrid to form 1
Me.DialogResult=Windows.Forms.DialogResult.OK
End Sub
Form 1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Form2.ShowDialog = Windows.Forms.DialogResult.OK Then
'Getthe value from form 2
invoice_items.Rows.Add()
End If
End Sub

VB restart form

I created a button and I need it to restart the form
I have no idea how to work on the visual basic what should i write
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
Do you mean Application.Restart() ?
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Application.Restart()
End Sub
Although in Visual Basic this does the same as in C#, it restarts the application not just clears the form.
In order to reload the form you simply need to do this in the form's Load event.
Me.Close()
Me.Show()
Try This..
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Application.Restart()
End Sub