Dynamically assigning worksheet name while inserting/moving sheets.

zensathish

New Member
Joined
May 28, 2019
Messages
6
Hi All,

I am new to this forum and this is my first post.

I have multiple text files, which I am locating using

Code:
Application.ActiveWorkbook.Worksheets

once the text files are located, I open it using
Code:
 Workbooks.OpenText Filename:= _
        sFolder & "/CONTRACT" _
        , Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
        Comma:=False, Space:=False, Other:=True, OtherChar:="*", FieldInfo:= _
        Array(Array(1, 5), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True

after I open the files, I move it to the current excel (excel name MC9.xlsm) using

Code:
    Windows("CONTRACT").Activate
    Sheets("CONTRACT").Select
    Sheets("CONTRACT").Move After:=Workbooks("MC9.xlsm").Sheets(2)

Here the file name is hard coded as "MC9.xlsm". I need to know how to get the workbook name and assign it in the below code

Code:
Sheets("CONTRACT").Move After:=Workbooks("MC9.xlsm").Sheets(2)

Your support would be much appreciated.

Regards,
Zen.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,224,830
Messages
6,181,227
Members
453,025
Latest member
Hannah_Pham93

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top