Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Insert first row in multiple excel files in given folder

Posted on 2013-01-25
2
Medium Priority
?
366 Views
Last Modified: 2013-01-25
Dear Experts:

I would like to run a macro that performs the following action:

I got hundreds of xlsm-files in C:\temp\

- I would like to insert a row at the very top of each workbook (each workbook contains just one worksheet named 'temp').

- This newly created first row has to have the following entries for A1, B1, C1, D1:
Item Number, Customer, Street, Items.

- The first row should be formatted to repeat with each page break (rows to repeat at top)

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 2000 total points
ID: 38817988
Try

Sub insertheaders()
    Dim pth As String, fnam As String, wb As Workbook
    pth = "c:\temp\"
    fnam = Dir(pth & "*.xls?")
    Do While fnam <> ""
        Set wb = Workbooks.Open(pth & fnam)
        wb.ActiveSheet.Range("A1").EntireRow.Insert
        wb.ActiveSheet.Range("A1:D1") = Split("Item Number, Customer, Street, Items", ",")
        wb.Close True
        fnam = Dir
    Loop
End Sub
0
 

Author Comment

by:AndreasHermle
ID: 38818695
Dear ssagibh:

thank you very much for your great help. Works great although I needed to make a slight change on the variable declaration:

Dim wb As Variant

And I added
wb.ActiveSheet.PageSetup.PrintTitleRows = "$1:$1" for the header to be repeated on page breaks.

Anyhow, thank you very much for your great and swift support. I really appreciate it.

Regards, Andreas
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question