We help IT Professionals succeed at work.
Get Started

Visual Basic

297 Views
Last Modified: 2012-08-14
It is been about 2 years that I haven't programmed with VB so please be clear in your comments. I am trying to add a button on my form that would copy an excel file from a share drive and deletes all its tabs and inserts 4 new sheets. Like sheet1, sheet2, sheet3 and sheet4. Then it asks the user to name that file. Then it saves that copy into the desktop.
Also, the code needs to open that saved file and runs one of its macros.
I tried to do as much as I could but since this is urgent I couldn't research more about this:
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
    Dim oExcel As Object
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value
        Dim dtmTest As Date
        dtmTest = DateValue(Now)
        Dim FileToCopy As String
        Dim NewCopy As String

        MessageBox.Show(dtmTest)
        FileToCopy = "C:\Users\Owner\Documents\test.txt"
        NewCopy = "C:\Users\Owner\Documents\NewTest.txt"
        xlWorkBook.Close()
        xlApp.Quit()

        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)

        MsgBox("Excel file created , you can find the file c:\")
    End Sub

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

Open in new window



Thank you all for your help,
Paul
Comment
Watch Question
Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
Unlock 1 Answer and 19 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE