Joe4
MrExcel MVP, Junior Admin
- Joined
- Aug 1, 2002
- Messages
- 74,077
- Office Version
- 365
- Platform
- Windows
We are writing a macro that will take a large Excel data file and convert it to a prn file so that we can import into our software.
We discovered that when creating a prn file, Excel wraps characters after space 240 to the next line. We were able to work around that by using the code found in Microsoft Knowledge Base Article - 131554 ( http://support.microsoft.com/default.aspx?scid=kb;en-us;131554 ).
However, we have a little "twist". A few of the fields are date fields, and are in a date format. We need them to be in the prn file in "mmddyyyy" format. Unfortunately, no matter which format we put it in, the code from the MS Knowledge Base puts it in numeric format (i.e. 9/17/03 exports as 37881).
Using the code from the MS Knowledge Base, what can I do to get the date to export in my desired format (i.e. 09172003)? I can write code to build a text string from the actual date, but I must be putting in the wrong place because it isn't working. Or is there a easier or better way?
BTW, here is code I wrote:
We discovered that when creating a prn file, Excel wraps characters after space 240 to the next line. We were able to work around that by using the code found in Microsoft Knowledge Base Article - 131554 ( http://support.microsoft.com/default.aspx?scid=kb;en-us;131554 ).
However, we have a little "twist". A few of the fields are date fields, and are in a date format. We need them to be in the prn file in "mmddyyyy" format. Unfortunately, no matter which format we put it in, the code from the MS Knowledge Base puts it in numeric format (i.e. 9/17/03 exports as 37881).
Using the code from the MS Knowledge Base, what can I do to get the date to export in my desired format (i.e. 09172003)? I can write code to build a text string from the actual date, but I must be putting in the wrong place because it isn't working. Or is there a easier or better way?
BTW, here is code I wrote:
Code:
If IsDate(Cells(RowNum, ColNum)) Then
Dim MyMonth, MyDay, MyYear As String
MyMonth = Month(Cells(RowNum, ColNum))
If Len(MyMonth) = 1 Then MyMonth = "0" & MyMonth
MyDay = Day(Cells(RowNum, ColNum))
If Len(MyDay) = 1 Then MyDay = "0" & MyDay
MyYear = Year(Cells(RowNum, ColNum))
Cells(RowNum, ColNum).NumberFormat = "@"
Cells(RowNum, ColNum) = MyMonth & MyDay & MyYear
End If