By ygoyal578@gmail.com on Friday, 29 May 2020
Posted in Excel
Replies 1
Likes 0
Views 8K
Votes 0
Hello Frnds,
I'm looking for the solution where
  1. File selection could be done from user.[/*]
  2. Based on the selected file further action could be performed on that particular file.[/*]
  3. Based on my requirement I have tried writing the code but when the file is opening the macro does not execute there after. Please find below the code.[/*]
Sub FileCreation()
Dim FolderPath As String
Dim Filename As Variant
Dim openbook As Workbook
Dim file_name As Variant
Dim bFileSaveAs As Boolean

Application.ScreenUpdating = False
Filename = Application.GetOpenFilename(Title:="Select Configuration Template")
If Filename <> False Then
Set openbook = Application.Workbooks.Open(Filename)
ThisWorkbook.Activate
openbook.Worksheets("User Master").Activate
If Range("C6") <> "" Then
ActiveSheet.Range("B6:T").Copy
Workbooks.Add
Worksheets("User Master").Add
Range("A1").Select
ActiveSheet.Paste
Else
Range("A1:XFD1048576").Select
Selection.Copy
Workbooks.Add
Worksheets("User Master").Add
Range("A1").Select
ActiveSheet.Paste
End If
bFileSaveAs = Application.Dialogs(xlDialogSaveAs).Show
    If Not bFileSaveAs Then MsgBox "User cancelled", vbCritical
ActiveWorkbook.Close
Worksheets("Community").Activate
Range("A1:G1").Select
Range(Selection, Selection.End(xlDown)).Copy
Workbooks.Add
ActiveSheet.Paste
bFileSaveAs = Application.Dialogs(xlDialogSaveAs).Show
    If Not bFileSaveAs Then MsgBox "User cancelled", vbCritical
ActiveWorkbook.Close
Worksheets("web installer").Activate
Range("A1:ZZ1").Select
Range(Selection, Selection.End(xlDown)).Copy
Workbooks.Add
Worksheets("Invite Users").Add
Range("A1").Select
ActiveSheet.Paste
bFileSaveAs = Application.Dialogs(xlDialogSaveAs).Show
    If Not bFileSaveAs Then MsgBox "User cancelled", vbCritical
ActiveWorkbook.Close
Else
MsgBox "User Cancelled the Operation"
End If
End Sub
You can do it easily.
Add the following content in a VBS file (e.g. example.vbs). This is only a text file that you can write using Notepad:
'Code should be placed in a .vbs file
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\path\to\my\excel\file\myExcelMacroFile.xlsm'!MyModule.MyFunctionName"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
Then you can double clic on the VBS file to execute it.
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post