Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Copy-Paste & save as macro


Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2005, 07:51 PM
pool_cup pool_cup is offline
Freshman
 
Join Date: Sep 2004
Posts: 32
Cool Copy-Paste & save as macro


hELLO!
Is there some way to automate a task of copying a sheet values of an Excel file, pasting them into a text file and rename it to another extension rather txt?

I have already done this task using an excel macro but it is not recognized by the program that uses the resulting file as an input, I think that maybe it gets corrupted during the process...The truth is that it does work when I do it manually, I copy the values, paste them into a text file and rename the file to .epc...weird isnt it?

here is the code, hope to have another point of view

Code:
Sub Button3_Click() Dim Tb As Workbook, Tn As String Dim Sb As Workbook, Sn As String Dim SPath As String On Error GoTo NBG Application.ScreenUpdating = False Application.DisplayAlerts = False Set Tb = ThisWorkbook Set Sb = Workbooks.Add Tb.Sheets("Sheet1").Cells.Copy 'change to your sheet name Sb.Sheets(1).Cells.PasteSpecial xlValues Application.CutCopyMode = False Sn = Left(Tb.Name, InStr(1, Tb.Name, ".xl", 1) - 1) SPath = Tb.Path & "\" & Sn & ".epc" Sb.SaveAs SPath, xlTextPrinter, CreateBackup:=False NBG: 'Errors If Err.Number <> 0 Then MsgBox "Error number " & Err.Number & vbLf & Err.Description, vbCritical, "ERROR" End If Err.Clear Sb.Close False Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub
Reply With Quote
  #2  
Old 01-09-2005, 09:11 AM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

You can save Excel workbooks (1 sheet at a time though) as a text file (file > saveas > textfile).
But I don't know for sure there is a way to change a file extension programmatically.
Which is your specific reason you want to do such thing?
Reply With Quote
  #3  
Old 01-13-2005, 03:24 PM
pool_cup pool_cup is offline
Freshman
 
Join Date: Sep 2004
Posts: 32
Default

I need to generate this file with such extension to feed another program that is going to use it.
Reply With Quote
  #4  
Old 01-17-2005, 01:39 AM
Eoin Eoin is offline
Centurion
 
Join Date: Jul 2004
Location: Ireland, Dublin
Posts: 139
Default

Try saving the file as italkid sujested and then use the filecopy command to rename the file and it's extension.

Just a though

Regards
__________________
Eoin
_______________________________________
I can resist any thing, but temptation –Oscar Wilde
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->