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

  • SEARCH
  • Home
  • 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 6992375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:37:35+00:00 2026-05-27T19:37:35+00:00

i am writting a code to copy a sheet in excel from one workbook

  • 0

i am writting a code to copy a sheet in excel from one workbook to another and I’m having the following issue :

 Set xlsAppSource = CreateObject("Excel.Application")
 Set xlsWBSource = xlsAppSource.Workbooks.Open(strWBSource)  

 Set xlsAppCible = CreateObject("Excel.Application")
 Set xlsWBCible = xlsAppCible.Workbooks.Open(strWBCible)

 xlsWBSource.Sheets(1).Copy before:= xlsWBSource.Sheets(1)

And I get ERROR 1004.

I know the error comes from :

xlsWBSource.Sheets(1) and xlsWBSource.Sheets(1)

because when change the last statement to :

xlsWBSource.activate

ActiveWorkbook.Sheets(strSheetSource).Copy before:= [any working sheet]

it works.

But As I cannot activate the 2 workbooks it’s not a way to solve my problem.

Any ideas why it doesnt work ?

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-05-27T19:37:36+00:00Added an answer on May 27, 2026 at 7:37 pm

    If you are tring to copy from from xlsWBSource to xlsWBCible then you should only use one instance of Excel , you are currently opening two separate versions with your two CreateObjects – the two separate instances can’t “talk”, hence the error

    Whereas this will work:

    Set xlsAppSource = CreateObject("Excel.Application")
    Set xlsWBSource = xlsAppSource.Workbooks.Open(strWbsource)
    Set xlsWBcible = xlsAppSource.Workbooks.Open(strWBcible)
    xlsWBSource.Sheets(1).Copy before:=xlsWBcible.Sheets(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I copy and paste code from this URL for creating and reading/writing a proc
I am trying to learn and writting this part of code. while testing few
After writing code to populate textboxes from an object, such as: txtFirstName.Text = customer.FirstName;
When I am writing code in Python, I often need to remove items from
I am writing code to migrate data from our live Access database to a
I am writing some code to update an application by fetching new dlls from
I am writing a bash script to copy a file from a remote server,
I'm trying to create a directory and copy files to it. The code I've
see by writting some code here we select that code & press ctrl +
I'm writing code that check files path calculate hash (SHA1) and copy them. I

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.