Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8379737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:16:18+00:00 2026-06-09T16:16:18+00:00

I am attempting to create a subroutine that prompts the user to select a

  • 0

I am attempting to create a subroutine that prompts the user to select a workbook and then adds the first worksheet of the selected workbook as a tab in the existing (active) workbook. Then names the new tab “Data”. Here is the code I am using so far:

Sub getworkbook()
' Get workbook...
Dim ws As Worksheet
Dim filter As String
Dim targetWorkbook As Workbook

Set targetWorkbook = Application.ActiveWorkbook

' get the customer workbook
filter = "Text files (*.xlsx),*.xlsx"
caption = "Please Select an input file "
ws = Application.GetOpenFilename(filter, , caption)

ws.Add After:=Sheets(Sheets.Count)

ws.Name = "DATA"

End Sub

This code doesn’t seem to be working and is returning the following error:

“ws.Add” method or With Block not set.

Any help is appreciated.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:16:20+00:00Added an answer on June 9, 2026 at 4:16 pm

    You have declared ws as a worksheet and GetOpenFilename is returning a File name. I would recommend reading my post in this link:

    Is this what you are trying?

    Note: I have not done any error handling. I am sure you can take care of that.

    Sub getworkbook()
        ' Get workbook...
        Dim ws As Worksheet
        Dim filter As String
        Dim targetWorkbook As Workbook, wb As Workbook
        Dim Ret As Variant
    
        Set targetWorkbook = Application.ActiveWorkbook
    
        ' get the customer workbook
        filter = "Text files (*.xlsx),*.xlsx"
        Caption = "Please Select an input file "
        Ret = Application.GetOpenFilename(filter, , Caption)
    
        If Ret = False Then Exit Sub
    
        Set wb = Workbooks.Open(Ret)
    
        wb.Sheets(1).Move After:=targetWorkbook.Sheets(targetWorkbook.Sheets.Count)
    
        ActiveSheet.Name = "DATA"
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to create an xquery expression that will return selected nodes but will
While attempting to create a replacement tablespace for USER, I accidentally created a datafile
I am attempting to create a report, utilizing a matrix, that only displays columns
I'm attempting to create a single Controller class to handle all foreseeable surveys that
I'm attempting to create a Parcelable class in Android so that I can pass
I am attempting to create an inbound Mule endpoint that will receive Syslog messages
I am attempting to allow a user to select an image from the photo
Attempting to create a filter select to find schedules with coursedates within a given
I'm attempting to create a new forum on an existing forum. I can create
So I am attempting to create a search field that will filter contacts on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.