unanswered How to Peform action on any file without opening it using VBA

  • ygoyal578@gmail.com
  • ygoyal578@gmail.com's Avatar Topic Author
  • Offline
More
1 month 2 weeks ago #2271 by ygoyal578@gmail.com
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

Please Log in or Create an account to join the conversation.

Moderators: jaychivoExcelfansqiuhongkun