how to read workbook name and default while inserting a sheet.

Status
Not open for further replies.

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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Status
Not open for further replies.

Forum statistics

Threads
1,214,827
Messages
6,121,809
Members
449,048
Latest member
greyangel23

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