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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,224,845
Messages
6,181,298
Members
453,030
Latest member
PG626

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