Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2007, 10:06 AM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert filename in several spreadsheets

I would like to delete unused rows and insert the filename in column Z of several spreadsheets. Each spreadsheet has a title so I would like to insert the title "Original File" in column Z followed by the filename in the used range for col Z. For each spreadsheet, I would also like to delete unused rows. Somewhere in here, I think I need to determine the last used row (even if there are blank rows) in order to insert the filename in the appropriate range. Each file has 1 worksheet. Can you help me put this together?

The macro recorder gave me this piece of code:

Range("R2").Select
ActiveCell.FormulaR1C1 = "Original File"
    Range("R3").Select
    ActiveCell.FormulaR1C1 = "=MID(CELL(""filename""),SEARCH(""["",CELL(""filename""))+1,SEARCH(""]"",CELL(""filename""))-SEARCH(""["",CELL(""filename""))-1)"

Selection.Copy
Range("R4:R28").Select
ActiveSheet.Paste

I was able to gather this code to loop through the file names in the directory:

For Each vafilename In .FoundFiles
  updatefiles (vafilename)
Next vafilename

Thanks for taking the time to help.
nori233

 
Old January 19th, 2007, 09:33 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Nori 233

In my opinion, I will use Workbook_BeforePrint Event. Do as the follow step

1 Open File and Activate the Visual Basic Editor (Press Alt+F11)
2 Goto Project Explorer window (Press Ctrl+R)
3 Double Click Thisworkbook Icon
4 Click Left Combobox On Coding Window Choose Workbook
5 Click Right Combobox On Coding Window Choose BeforePrint
6 Copy the follow code then paste inside the procedure

dim sht As Worksheet
For each sht In thisworkbook.Worksheets
 sht.pagesetup.leftfooter = thisworkbook.name
Next

Hope it will be helpful information for you.

N. Yauvasuta





Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting data from excel spreadsheets Neil1234567 Access VBA 2 October 16th, 2007 07:28 AM
Import spreadsheets for Sarbanes-Oxley reporting makkerc Excel VBA 6 August 29th, 2007 08:03 AM
Pasting into spreadsheets IainAL VB How-To 0 April 23rd, 2007 04:33 AM
Extracting data from Spreadsheets in a folder IainAL VB How-To 2 April 20th, 2007 02:57 AM
Import Multiple Unknown Excel Spreadsheets in .Net bcarmen Excel VBA 1 January 31st, 2005 04:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.