breynolds0431
Active Member
- Joined
- Feb 15, 2013
- Messages
- 303
- Office Version
- 365
- 2016
- Platform
- Windows
Hello:
I have a semi-working macro that I discovered primarily with Recording. The premise is to have a main workbook with two buttons. One to open a dialogue box, navigate to a csv file, copy the contents, and paste into a predetermined tab of the main workbook. The second button does the same thing, but to an updated csv file. Then another tab analyzes for any variances. It works fine outside of the program that is handling our excel files. The problem is with the line of vba which states "Windows("PS&R Variance Anaylsis.xlsm").Activate. When the excel file is loaded into this other program, it doesn't recognize the Window name. Does anyone see an alternative to the Windows().Activate line?
Also, and this may kill two birds with one stone, but when the open-file dialogue box opens and the user hits cancel the active worksheet is copied into the destination. Is there a way to stop that?
I have a semi-working macro that I discovered primarily with Recording. The premise is to have a main workbook with two buttons. One to open a dialogue box, navigate to a csv file, copy the contents, and paste into a predetermined tab of the main workbook. The second button does the same thing, but to an updated csv file. Then another tab analyzes for any variances. It works fine outside of the program that is handling our excel files. The problem is with the line of vba which states "Windows("PS&R Variance Anaylsis.xlsm").Activate. When the excel file is loaded into this other program, it doesn't recognize the Window name. Does anyone see an alternative to the Windows().Activate line?
Also, and this may kill two birds with one stone, but when the open-file dialogue box opens and the user hits cancel the active worksheet is copied into the destination. Is there a way to stop that?
Code:
Sub GetNewPSR()
'
' GetNewPSR Macro
'
Application.Dialogs(xlDialogOpen).Show Arg1:="*.*"
Cells.Select
Selection.Copy
[U]Windows("PS&R Variance Analysis.xlsm")[/U].Activate
Sheets("New PSR").Select
Range("A1").Select
ActiveSheet.Paste
Dim Rng As Range, dn As Range
If Application.CountA(Worksheets("New PSR").Range("A:A"), Target) > 1000 Then
MsgBox "TOO MANY ROWS OF DATA. This Variance Analysis is only capable of analyzing 1,000 rows of data. Rerun Settlement in HFS."
Worksheets("Analysis").Visible = False
Worksheets("No Go").Visible = True
Worksheets("Instructions").Visible = False
Worksheets("Old PSR").Visible = False
Worksheets("New PSR").Visible = False
Sheets("No Go").Select
Exit Sub
End If
Sheets("Instructions").Activate
End Sub