• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X Scripting - Skill
  3. BOM EXCEL - VBA Macro to transfer content of a cell to a...

Stats

  • Replies 1
  • Subscribers 17
  • Views 692
  • Members are here 0
More Content

BOM EXCEL - VBA Macro to transfer content of a cell to a *.lst file, for OrCAD processing

andakConsultingLtd
andakConsultingLtd 3 months ago

Hello community,

I’ve manually soldered many components, and I found it very frustrating to constantly search for the components from the BOM in Allegro/OrCAD. Even with the BOM open on one screen and the PCB on another, and with some lists made via copy/paste, the process is tedious and even annoying. So I created this small Excel macro, which I’d like to share with you, that transfers the content of the selected cell into a text file with the *.lst extension. You can point this file to a script/SKILL that highlights those components. Change the extension from txt to bas (security blocks it otherwise).

If you don't know how to handle a VBA, don;t worry, there are plenty resources on the web.

Fullscreen cellContentToPCB.txt Download
Attribute VB_Name = "Module1"
' This macro is provided to you free of charge by Andak Consulting, Jun 2025.
' No warranty is provided, and Andak Consulting cannot be held liable for any damage caused by the use of this script, in any form.
' You may redistribute this script, and you may even use it for commercial purposes.
' The only requirement is to keep the header of this file.

' usage
' we use this with BOM files, when manually soldering components
' it comes in handy to pass the selected cell content to OrCAD PCB/Allegro for processing (we use add color in shadow mode).
' open your BOM in EXCEL. The refdes column should contain comma separated values like this: R8,R11,R13,R15,R24,R29
' select one cell and run this macro
' the macro creates a file under your %HOME%\pcbenv folder, named excelTransfer.lst
' the macro replaces the comma with white spaces and also removed the background color of the excel line (we use this colors in our process)
' we recommend customizing your ribbon to quickly acces this the macro command. there's plenty documentation on the web on how to do this and preferably save this under personal.xlsb
' use the generated file (lst) in OrCAD PCB/ Allegro. We recommend either recoding a script or writing a SKILL, whichever comes in handy for you.

' rev history
' 1.0, original release, Andak Consulting, 02 July 2025

Sub ExportSelectedCellToFile()
    Dim cellContent As String
    Dim modifiedContent As String
    Dim filePath As String
    Dim homePath As String

    ' Check if a single cell is selected
    If TypeName(Selection) <> "Range" Or Selection.Cells.Count > 1 Then
        MsgBox "Please select a single cell.", vbExclamation
        Exit Sub
    End If

    ' Get the HOME environment variable
    homePath = Environ("HOME")
    If homePath = "" Then
        MsgBox "The HOME environment variable is not set.", vbCritical
        Exit Sub
    End If

    ' Construct the full file path
    filePath = homePath & "\pcbenv\excelTransfer.lst" ' You can change the filename here

    ' Read the content from the selected cell
    cellContent = Selection.Value

    ' Replace commas with spaces
    modifiedContent = Replace(cellContent, ",", " ")

    ' Write to file, overwriting existing content
    Dim fileNum As Integer
    fileNum = FreeFile
    Open filePath For Output As #fileNum
    Print #fileNum, modifiedContent
    Close #fileNum

    ' Remove fill color from the entire row of the selected cell
    selectedRow = Selection.Row
    Rows(selectedRow).Interior.ColorIndex = xlNone
End Sub

Below, I’m also sharing my usage script, but you’ll need to update the path to the transfer file (based on your env %HOME%)and manage how you launch it (workflow item, funckey, menu item etc) according to your preferences.

# Allegro script
#    file: Q:/ADK_SITE/pcb/scripts/excelListHilight.scr
#    start time: Wed Jul  2 20:05:24 2025
#    Version: 23.1-2023 S010 (4290465) Windows SPB 64-bit Edition
version 23.1

setwindow pcb
deassign color 
setwindow form.find
FORM find find_list Name 
FORM find find_name *
setwindow pcb
prepopup 0 0
done 
assign color 
setwindow form.find
FORM find find_list List 
FORM find find_by_name

#change below path with the one based on your %HOME% variable
fillin "C:/Work/pcbenv/excelTransfer.lst"
setwindow pcb
prepopup 0 0
done 
#    stop time: Wed Jul  2 20:06:21 2025

  • Cancel
  • Sign in to reply
Parents
  • Hoangkhoipcb
    Hoangkhoipcb 3 months ago

    Hello Andak

    Your idea is perfect. I have another idea: use the function axlClipboardGetText() as well—everyone refers to this method.

    Usage:

    load("*.il")

    copy select value Refdes Excel

    type ->cmd  "assign_color_sym"

    axlCmdRegister("assign_color_sym" 'assign_color_sym)
    (defun assign_color_sym ()
    foreach(item parseString(axlClipboardGetText() ",")
    refdes = axlStringRemoveSpaces(item)
    if(refdes != "" then
    if(index(refdes "\t") then
    rexCompile("\t")
    refdes = rexReplace(refdes "" 0)
    )
    if(index(refdes "\n") then
    rexCompile("\n")
    refdes = rexReplace(refdes "" 0)
    )
    refdes = upperCase(refdes)
    syms = setof(e axlDBGetDesign()->symbols e->refdes == refdes)
    if(syms != nil then
    axlCustomColorObject(syms nil)
    )
    )
    )
    )

    Regard,

    HoangKhoi.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Hoangkhoipcb
    Hoangkhoipcb 3 months ago

    Hello Andak

    Your idea is perfect. I have another idea: use the function axlClipboardGetText() as well—everyone refers to this method.

    Usage:

    load("*.il")

    copy select value Refdes Excel

    type ->cmd  "assign_color_sym"

    axlCmdRegister("assign_color_sym" 'assign_color_sym)
    (defun assign_color_sym ()
    foreach(item parseString(axlClipboardGetText() ",")
    refdes = axlStringRemoveSpaces(item)
    if(refdes != "" then
    if(index(refdes "\t") then
    rexCompile("\t")
    refdes = rexReplace(refdes "" 0)
    )
    if(index(refdes "\n") then
    rexCompile("\n")
    refdes = rexReplace(refdes "" 0)
    )
    refdes = upperCase(refdes)
    syms = setof(e axlDBGetDesign()->symbols e->refdes == refdes)
    if(syms != nil then
    axlCustomColorObject(syms nil)
    )
    )
    )
    )

    Regard,

    HoangKhoi.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information