in reply to Re^3: which module to use?
in thread which module to use?

I have here a copy of the macro to leave my excel file like I wanted can you help me understand which modules I need to use?
These is the macro
Sub test12() ' ' test12 Macro ' ' Workbooks.Open Filename:="C:\Proyecto\csv\T3683.csv.xls" Range("A1:M1196").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With Columns("B:B").EntireColumn.AutoFit Columns("E:E").EntireColumn.AutoFit Columns("H:H").EntireColumn.AutoFit Columns("I:I").EntireColumn.AutoFit ActiveWindow.SmallScroll Down:=-24 Rows("1:10").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbov +e Rows("9:12").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbov +e Range("A14").Select ActiveCell.FormulaR1C1 = "PATENTE" Range("B14").Select ActiveCell.FormulaR1C1 = "pedimento" Columns("C:D").Select Selection.Cut Destination:=Columns("N:O") Columns("C:D").Select Range("D1").Activate Selection.Delete Shift:=xlToLeft Range("D14").Select Columns("C:C").ColumnWidth = 6.71 Range("C14").Select ActiveCell.FormulaR1C1 = "documento" Range("D14").Select ActiveCell.FormulaR1C1 = "fec entra" Range("E14").Select ActiveCell.FormulaR1C1 = "fec salida" Range("F14").Select ActiveCell.FormulaR1C1 = "RFC imp/exp" Range("G14").Select ActiveCell.FormulaR1C1 = "CURP" Range("H14").Select ActiveCell.FormulaR1C1 = "peso bruto" Range("J14").Select ActiveCell.FormulaR1C1 = "contribuciones" Range("K14").Select ActiveCell.FormulaR1C1 = "banco" Range("L14").Select ActiveCell.FormulaR1C1 = "ped orig" Range("M14").Select ActiveCell.FormulaR1C1 = "ped recfif" Columns("I:I").Select Selection.Delete Shift:=xlToLeft Range("A14:L14").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With Selection.Font.Bold = True With Selection.Font .ThemeColor = xlThemeColorLight2 .TintAndShade = 0.399975585192419 End With Range("E8").Select ActiveCell.FormulaR1C1 = _ "RELACION DE OPERACIONES CORRESPONDIENTES A LA SEMANA " With ActiveCell.Characters(Start:=1, Length:=53).Font .Name = "Arial" .FontStyle = "Normal" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With Range("E8").Select End Sub
I really apreciate your help
Thanks

Replies are listed 'Best First'.
Re^5: which module to use?
by Corion (Patriarch) on Jan 11, 2008 at 20:03 UTC

    As you already have the Visual Basic code, it's easy to translate that into Perl, if your code runs on Windows and you have the module Win32::OLE. Win32::OLE does (quite unsurprisingly) not work on operating systems that are not Windows.

    1. Start in small steps, don't translate all of the file at once
    2. At the top add the code to get an Excel instance (see Win32::OLE)
    3. Import the correct type library (using Win32::OLE::Const) or find the numeric values of all constants using Google
    4. Prefix $excel-> in front of every statement
    5. Replace every dot in VB with the arrow: s/\./->/g
    6. With ... .LineStyle = xlContinuous ...
      becomes
      my $foo = ...; $foo->LineStyle = xlContinous;

    Also see Using Win32::OLE and Excel - Tips and Tricks, Scripting data extraction from excel files in a directory. and the nodes I linked from there