I need help with a macro. When I run the macro, I need to set the current workbook as a variable. I want to then call that variable later.
Here is what I have and it doesn't work. I have two workbooks open. If I name them in the macro I can see it switc focus to each one. If I try to pass in a variable name, I get errors. Any ideas?
Posts by theath
-
-
Trying to write a script that will sit in one workbook. When initiated it wil prompt the user to select a workbook, copy the data from that workbook and paste it a table in the original workbook. Here is what I have so far, but when I run this I get an error when it gets to the paste function. It won't go back and set the focus on the original workbook. I have highlighted in red where the script errors out. I have tried a number of variations for that line, but can't seem to find one that works. Any ideas?
Code
Display MoreSub importData() Dim WB As Workbook Set WB = ThisWorkbook getData Copy Paste End Sub Sub getData() Dim fn Dim wbFrom As Workbook Dim ws As Worksheet Dim sSht As String On Error Resume Next fn = Application.GetOpenFilename If fn = False Then MsgBox "Nothing Chosen", vbCritical, "Select workbook" Else: Workbooks.Open fn Set wbFrom = ActiveWorkbook End If Set wbFrom = Nothing End Sub Sub Copy() Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy End Sub Sub Paste() [COLOR=#ff0000]ThisWorkbook.Worksheets.Select 'Also tried: ThisWorkbook.Worksheets ("DATA").Select WB.Worksheets. Select WB.Worksheets ("DATA").Select [/COLOR] Sheets("DATA").Select Range("Table1[Project Number]").Select Range("A1").Select ActiveSheet.Paste End Sub
-
Re: Save workbook as name combining text and cell value
Thanks!
I just found the answer on a suggested thread on this site! Worked perfectly. Even was able to format the date the way I would like.
I should have given up and come here two hours ago. Would have saved a few hairs from graying! -
When the excel file is opened I need to have it saved with a combination of text and a date that is contained within a particular cell.
The date is formatted mm/dd/yyyy. The file cannot be saved with "/" in the name.
I need to use the date contained in the cell.
Any ideas how I can do this?