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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:06:48+00:00 2026-05-23T22:06:48+00:00

I am trying to translate the VBA code found in this link into IronPython.

  • 0

I am trying to translate the VBA code found in this link into IronPython. Can anyone recommend a good VBA resource to explain how best to do this for a Python programmer?

I have all the Excel portions implemented, such as the treatment and use of objects, workbooks, worksheets, etc.

I will also settle for an explanation of this snippet of code:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Put the index value of the sheet into Arr. Ensure there
' are no duplicates. If Arr(N) is not zero, we've already
' loaded that element of Arr and thus have duplicate sheet
' names.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Arr(N) > 0 Then
    ErrorText = "Duplicate worksheet name in NameArray."
    SortWorksheetsByNameArray = False
    Exit Function
End If

why would Arr(N) ever NOT be greater than 0?

Here is my current code, which is broken:

def move_worksheets_according_to_list(self, name_list):
    wb = self.com_workbook
    temp_list = []
    for n in range(len(name_list)):
        if name_list.count(name_list[n]) > 1:
            raise Exception("Duplicate worksheet name in NameArray.")
        else:
            temp_list.append(wb.Worksheets(name_list[n]).Index)

    for m in range(len(temp_list)):
        for n in range(m, len(temp_list)):
            if temp_list[n] < temp_list[m]:
                l = temp_list[n]
                temp_list[n] = temp_list[m]
                temp_list[m] = l

    if not all(temp_list[i] <= temp_list[i+1] for i in xrange(len(temp_list)-1)):
        return False

    print "current order"
    for sheet in wb.Worksheets:
        print sheet.Name
    wb.Worksheets(name_list[0]).Move(Before=wb.Worksheets(1))
    #WB.Worksheets(NameArray(LBound(NameArray))).Move before:=WB.Worksheets(Arr(1))
    for n in range(len(name_list)-1):
        print 'moving ', name_list[n], 'before ', name_list[n+1]
        wb.Worksheets(name_list[n]).Move(Before=wb.Worksheets(name_list[n + 1]))

Note:

With this answer as reference, here is all I had to do:

def move_worksheets_according_to_list(self, name_list):
    wb = self.com_workbook
    l = []
    # since wb.Worksheets is a com_object, you can't use the "if _ in XXX"
    # construct without converting to a list first
    for s in wb.Worksheets:
        l.append(s.Name)

    for n in range(len(name_list)):
        if name_list[n] in l:
            wb.Worksheets(name_list[n]).Move(After=wb.Worksheets(wb.Worksheets.Count))
  • 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-23T22:06:49+00:00Added an answer on May 23, 2026 at 10:06 pm

    def move_worksheets_according_to_list(self, name_list):
    wb = self.com_workbook
    l = []
    # since wb.Worksheets is a com_object, you can’t use the “if _ in XXX”
    # construct without converting to a list first
    for s in wb.Worksheets:
    l.append(s.Name)

    for n in range(len(name_list)):
        if name_list[n] in l:
            wb.Worksheets(name_list[n]).Move(After=wb.Worksheets(wb.Worksheets.Count)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to translate this centering code snip in Objective-C into MonoTouch imageView.frame.origin.x
I am trying to translate this code from Prototype into the same thing in
I am trying to translate this code into Silverlight. Any suggestions for a replacement
I'm trying to translate this into C# code: Wait 5 seconds and then debit
Sometimes I still get stuck trying to translate procedural code into functional code. Is
I am trying to translate a C program into MIPS assembly code In my
I'm trying to translate this line of Javascript code to Jquery. The problem i'm
I'm trying to translate code from this thread in python: import sys from PyQt4.QtCore
I'm trying to translate some C# LINQ code into VB.NET and am stuck on
I am trying to translate this into Linq and cannot figure it out: SELECT

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.