Wrox Programmer Forums
|
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 July 2nd, 2012, 03:45 PM
Registered User
 
Join Date: Jul 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Conversion Macro

Hi. I'm somewhat new to the world of VBA. I need to create a macro that will open all .wk1 files in a directory and save them as .xls files. I would appreciate any help I can get. Thanks!
 
Old July 3rd, 2012, 09:32 AM
JP JP is offline
Authorized User
 
Join Date: Apr 2008
Posts: 57
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by gnt21 View Post
Hi. I'm somewhat new to the world of VBA. I need to create a macro that will open all .wk1 files in a directory and save them as .xls files. I would appreciate any help I can get. Thanks!
Welcome to the forum. Where are you stuck?
__________________
Regards,
JP
JP SoftTech
 
Old July 3rd, 2012, 09:40 AM
Registered User
 
Join Date: Jul 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

From the beginning actually. I have picked up stuff that others have developed, but have no experience developing macros for myself. I've been able to manipulate others for calculations, but haven't seen one like this before. Thanks!
 
Old July 4th, 2012, 08:44 PM
JP JP is offline
Authorized User
 
Join Date: Apr 2008
Posts: 57
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Use Workbooks.Open(filename) to open a file, and Workbook.SaveAs to save the file, specifying the format. The Visual Basic help has sample code for each method.

To open all files in a folder, try something like this:

(From http://stackoverflow.com/q/11152870/190829)

Code:
Sub OpenFiles()
Dim MyFolder As String
Dim MyFile As String
MyFolder = "C:\Myfiles"
MyFile = Dir(MyFolder & "\*.wk1")
Do While MyFile <> ""
  Workbooks.Open Filename:=MyFolder & "\" & MyFile
Loop
End Sub
__________________
Regards,
JP
JP SoftTech
 
Old July 5th, 2012, 05:21 PM
Registered User
 
Join Date: Jul 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to your help I have the opening and closing of files taken care of. I am partially there for the saving aspect. It will only save the first file as an .xls file and then closes everything else. Am I missing something in the way this is being looped? The code is below. You have been a life saver. I really appreciate it!!

Sub OpenAndSaveFiles()
Dim MyFolder As String
Dim MyFile As String
MyFolder = "C:\Documents and Settings\trichter\My Documents\Macro Testing\Wk1 to XLS\wk1-first level"
MyFile = Dir(MyFolder & "\*.wk1")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
ActiveWorkbook.SaveAs MyFile, FileFormat:=xlNormal
MyFile = Dir
Loop
Workbooks.Close
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
help me regarding conversion raj_yash22 ASP.NET 3.5 Professionals 2 December 22nd, 2009 07:57 AM
calling to xlam macro from macro inside xlsb SteveB Excel VBA 0 June 30th, 2008 06:43 PM
conversion gbilios C++ Programming 6 August 6th, 2004 06:13 PM
Macro Help! Jolin VB How-To 0 April 22nd, 2004 08:38 AM
Macro KennethMungwira Access 1 June 13th, 2003 12:00 AM





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