Sha256: 31d7352ec8d89e9cd42263c62b4b22b1be2c6e54cdc4aadd5bfc5bef2d865dd6

Contents?: true

Size: 1.2 KB

Versions: 23

Compression:

Stored size: 1.2 KB

Contents

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

#######################################################################
#
# An example of adding macros to an WriteXLSX file using VBA project file
# extracted from an existing Excel xlsm file.
#
# The +extract_vba.rb+ utility supplied with WriteXLSX can be used to extract
# the vbaProject.bin file.
#
# An embedded macro is connected to a form button on the worksheet.
#
# reverse(c), November 2012, John McNamara, jmcnamara@cpan.org
# convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
#

require 'rubygems'
require 'write_xlsx'

# Note the file extension should be .xlsm.
workbook  = WriteXLSX.new('macros.xlsm')
worksheet = workbook.add_worksheet

worksheet.set_column('A:A', 30)

# Add the VBA project binary.
workbook.add_vba_project('./vbaProject.bin')

# Show text for the end user.
worksheet.write('A3', 'Press the button to say hello.')

# Add a button tied to a macro in the VBA project.
worksheet.insert_button(
                        'B3',
                        :macro   => 'say_hello',
                        :caption => 'Press Me',
                        :width   => 80,
                        :height  => 30
                        )

workbook.close

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
write_xlsx-0.81.0 examples/macros.rb
write_xlsx-0.80.0 examples/macros.rb
write_xlsx-0.79.0 examples/macros.rb
write_xlsx-0.78.0 examples/macros.rb
write_xlsx-0.77.2 examples/macros.rb
write_xlsx-0.77.1 examples/macros.rb
write_xlsx-0.77.0 examples/macros.rb
write_xlsx-0.76.3 examples/macros.rb
write_xlsx-0.76.2 examples/macros.rb
write_xlsx-0.76.1 examples/macros.rb
write_xlsx-0.76.0 examples/macros.rb
write_xlsx-0.75.0 examples/macros.rb
write_xlsx-0.74.0 examples/macros.rb
write_xlsx-0.73.0 examples/macros.rb
write_xlsx-0.72.3.beta1 examples/macros.rb
write_xlsx-0.72.2 examples/macros.rb
write_xlsx-0.72.1 examples/macros.rb
write_xlsx-0.72.0 examples/macros.rb
write_xlsx-0.71.0 examples/macros.rb
write_xlsx-0.70.0 examples/macros.rb