Skip to main content
Support is Offline
Today is our off day. We are taking some rest and will come back stronger tomorrow
Official support hours
Monday To Friday
From 09:00 To 17:30
  Friday, 29 May 2020
  1 Replies
  7.5K Visits
0
Votes
Undo
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
3 years ago
·
#2147
0
Votes
Undo
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.
  • Page :
  • 1
There are no replies made for this post yet.