johnycoo 0 Newbie Poster

Hello everyone! I am new to vb. I have a macro at excel but i want to get it out as a vb file. When the file runs it should run the fuction I already have written. So all i want is t connect to a spesified exxcecl file and run this fuction.

Sub CreateWorkbooks()

Dim wbDest As Workbook
Dim wbSource As Workbook
Dim sht As Object
Dim strSavePath As String

On Error GoTo ErrorHandler

Application.ScreenUpdating = False

strSavePath = "C:\Temp\"

Set wbSource = ActiveWorkbook

For Each sht In wbSource.Sheets
Sheets(sht.Name).Select
    Range("A:A,1:6").Select
    Selection.Clear
Next

For Each sht In wbSource.Sheets
sht.Copy
Set wbDest = ActiveWorkbook
wbDest.SaveAs strSavePath & sht.Name
wbDest.SaveAs strSavePath & sht.Name, FileFormat:=xlHtml
wbDest.Close
Next

ActiveWorkbook.SaveAs Filename:="C:\Temp\admin.mht", FileFormat:=xlWebArchive, CreateBackup:=False

Application.ScreenUpdating = True

Exit Sub

ErrorHandler:
MsgBox "An error has occurred. Error number=" & Err.Number & ". Error description=" & Err.Description & "."
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.