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 3843938
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:00:36+00:00 2026-05-19T16:00:36+00:00

I am working an existing project which is base do Excel class to copy

  • 0

I am working an existing project which is base do Excel class to copy values from one worksheet A to another one B. There are some formulas and Addin functions in ws A cells. The copy codes are used to copy only values out to ws B as a result. Here is a block of simplified codes:

using Excel = Microsoft.Office.Interop.Excel;
....

object missing = System.Type.Missing;

Excel.Application app = new Excel.Application();
// Creating Excel application with source workbook in memory
Excel.Workbook workbook = app.Workbooks.Open("SourceA.xls",
  Excel.XlUpdateLinks.xlUpdateLinksNever,....);
...

app.Calculate() // Forcing to recalculate value in cells.
...

//create destination workbook
Excel.Workbook destWb = app.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.WorkSheet destSheet = (Excel.Worksheet)destWb.Worksheets[1];
Excel.Range destRange = (Excel.Range)destSheet.Cells[1, 1];
//rename sheet 1
destSheet.Name = "wsB Report";

//Set Source Data Range from 
Excel.WorkSheet sourceWA = (Excel.Worksheet)workbook.Worksheets["wsA"];
//Get the predefined named range "DataRange" from source wsA
Excel.Range sourceRange = sourceWA.get_Range("DataRange", missing);
//copy data
sourceRange.Copy(missing);

//paste values and number formats
destRange.PasteSpecial(Excel.XlPasteType.xlPasteValuesAndNumberFormats,
    Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, missing, missing);
//paste formats
destRange.PasteSpecial(Excel.XlPasteType.xlPasteFormats,
    Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, missing, missing);
//paste column widths
destRange.PasteSpecial(Excel.XlPasteType.xlPasteColumnWidths,
    Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, missing, missing);
....

destWb.SaveAs("destB.xls", missing, ....);

The problem I have is that the copies cells in destB.xls are all marked as “#NAME?”. They should be values copied. I open the source excel file and I can see the data in the source range are updated with values. However, when I run my codes, the values seem not available.

I guess that the Excel application I created in my codes may not have Macro enabled. This may be reason values cannot be copied. For example, when I open the source excel file, I’ll see a prompt to enable or disable Macros. If I click on Enable button, the excel will take some time to display values in data cells.

If that is the reason, is there any way in codes to enable Macro so that all formulas in cells will be able to update values?

Another reason might be caused by OS or Windows security updates. Not sure if any Windows security settings may affect Excel macros. If this is the case, should I change Windows security level or any way to force Macros enabled in my project?

By the way, my project runs in Windows XP and Windows 2008 Server, with Office Excel 2003 installed. The project was done in VS 2008.

  • 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-19T16:00:37+00:00Added an answer on May 19, 2026 at 4:00 pm

    I went further into my codes and I found that by making Excel app visible, I’d able to see what actually happened. As Ben Voigt‘s suggestion, the security settings for Macro can be done in Excel, but in codes, you can force to execute any VBA-like codes no matter what the setting is. Here are some codes to make Excel visible and see all the prompt dialogs:

    Excel.Application app = new Excel.Application();
    Excel.Workbook workbook = app.Workbooks.Open("SourceA.xls", ...);
    app.Visible = true;       //set to 'true' when debbugging, Exec is visible
    app.DisplayAlerts = true; //enable all the prompt alerts for debug. 
    ...
    

    For example, I rebuild links in my C# codes, set values in cells and refresh or calculate values(simulate F9). By making Excel visible, I saw what was going on and found bugs in my codes which did not do what I want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an existing project, setup by another coder. I'm having some
I am working on a C++ project which has a huge code base and
I'm working on a project which stores single images and text files in one
I'm working on an existing Xcode 3.2.2 Universal iPhone OS project which is already
I'm working on a project which means customising an existing application (JasperServer 3.7.1) which
While working on an existing project I suddenly got the following error when trying
I am working on implementing Zend Framework within an existing project that has a
I'm working with an existing XML document which has a structure (in part) like
I am working on some schema changes to an existing database. I backed up
I'm currently working on a large implementation of Class::DBI for an existing database structure,

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.