VBA Activating Sheet names

Hello.
I have this code in workbook. I am stating the sheets name to activate to jump back and forth. Is this necessary? I am looking for an easier way in case I change the sheet name and not be required to change the code. I hope I am clear.

Here is the code See bold lines
Workbooks.Add
    ChDir "N:\Syn"
   
    ActiveWorkbook.SaveAs Filename:="N:\Syn\bbbentpo.txt", FileFormat:=xlText, _
        CreateBackup:=False
 

   Windows("PullOrderbruce.xlsm").Activate

Sheets("output").Select
    Application.Goto Reference:="DIPO"
    Selection.Copy
    Windows("bbbentpo.txt").Activate    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
    ActiveWorkbook.SaveAs Filename:="N:\Syn\bbbentpo.txt", FileFormat:=xlText, _
        CreateBackup:=False
   
Windows("PullOrderbruce.xlsm").Activate
cebu1014Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
Assuming the correct workbook to start:
Dim wbk1 as workbook, wbk2 as workbook
set wbk1 = activeworkbook
set wbk2 = Workbooks.Add
    ChDir "N:\Syn"
    
    wbk2.SaveAs Filename:="N:\Syn\bbbentpo.txt", FileFormat:=xlText, _
        CreateBackup:=False
 

   wbk1.Activate

Sheets("output").Select
    Application.Goto Reference:="DIPO"
    Selection.Copy
    wbk2.Activate    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    wbk2.SaveAs Filename:="N:\Syn\bbbentpo.txt", FileFormat:=xlText, _
        CreateBackup:=False
    
wbk1.Activate

Open in new window


It is generally unnecessary to activate workbooks or sheets at all in order to manipulate them though.
zorvek (Kevin Jones)ConsultantCommented:
This should be all you need:

    Workbooks.Add
    ActiveWorkbook.SaveAs Filename:="N:\Syn\bbbentpo.txt", FileFormat:=xlText, CreateBackup:=False
    Workbooks("PullOrderbruce.xlsm").Sheets("output").Range("DIPO").Copy
    With Workbooks("bbbentpo.txt")
        .Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        .SaveAs Filename:="N:\Syn\bbbentpo.txt", FileFormat:=xlText, CreateBackup:=False
        .Close
    End With

Kevin
cebu1014Author Commented:
Rorya
You got the right idea. However, I get this message and and highlights line 15.
Here..

Wrong number of arguments or invalid property assignment.
It did add wbk2.

Thanks
Rory ArchibaldCommented:
Sorry - that should be 2 lines:
wbk2.Activate    
Range("A1").Select

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cebu1014Author Commented:
THANKS FOR YOUR QUICK RESPONSE
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.