Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel Password and carving out Tab name
    primarykey
    data
    text
    <p>I'm in the process of setting up a Macro to open up all files in a directory and copy a certain tab from each into a combined file (merge them in one workbook). I have two problems. Firstly the files are password protected - So when I use this line it opens the file.</p> <pre><code>Set gwkbInputdata = Workbooks.Open(gRnCT_File_Loc &amp; gsInputFileName) </code></pre> <p>However when it's password protected it fails. So I added the following to the end but it still fails.</p> <pre><code>Set gwkbInputdata = Workbooks.Open(gRnCT_File_Loc &amp; gsInputFileName),Password = "openfile" </code></pre> <p>2nd issue - When I copy the tabs (sheets) in I want to name them with the file name I took them from. However the file name is too long - So I want to take the name up to the first space (e.g. "Test file May 13" = sheet name "Test"). How do I get this code to work.</p> <p>Any help greatly appreciated.</p> <p>Full code below:</p> <p><strong>* gRnCT_File_Loc = Directory location. *</strong> gsInputFileName = File Name.</p> <pre><code>Code to date: Sub Pulldata() Application.ScreenUpdating = False Application.DisplayAlerts = False Set gRwksconfigeration = Sheets(gcsConfigSheetName) gRnCT_File_Loc = gRwksconfigeration.Range(CT_File_Loc) gRnCT_Tab_Search = gRwksconfigeration.Range(CT_Tab_Search) gsInputFileName = Dir(gRnCT_File_Loc) Set gwkscurrent = ActiveWorkbook For Each ws In ThisWorkbook.Worksheets If ws.Name &lt;&gt; gcsConfigSheetName Then ws.Delete Next ws Do On Error GoTo err: Set gwkbInputdata = Workbooks.Open(gRnCT_File_Loc &amp; gsInputFileName) On Error GoTo 0 On Error GoTo err1: With Sheets(gRnCT_Tab_Search) On Error GoTo 0 End With gsInputFileName = Dir Loop Until gsInputFileName = vbNullString Application.ScreenUpdating = True Application.DisplayAlerts = True Exit Sub err: MsgBox ("No files or files in incorrect format in " &amp; gRnCT_File_Loc) Application.ScreenUpdating = True Application.DisplayAlerts = True Exit Sub err1: MsgBox ("Sheet " &amp; gRnCT_Tab_Search &amp; " doesn't exist in file " &amp; gsInputFileName) Application.ScreenUpdating = True Application.DisplayAlerts = True Resume Next End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload