Hi AJW
yes Iam awake again, here is some very simple code as example for you
Option Explicit
Option Base 1
Public TextRange As String
Public TextData(4)
Public Rw As Integer, Cl As Byte
Public Path As String
Public FName As String
Public Fnum As Integer
Public Count As Integer
'TEXT DUMP Excel Workbook ; Insomniac 2003
Private Sub ALLOFF()
Application.IgnoreRemoteRequests = True 'disable system
Application.Calculation = xlCalculationManual 'disable calculation
Application.EnableEvents = False 'disable events
Application.ScreenUpdating = False 'prevent screen flicker
End Sub
Private Sub ALLON()
Application.IgnoreRemoteRequests = False
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
Public Sub TextDump()
ALLOFF
Count = Application.WorksheetFunction.CountA(Sheets("DATA").Range("A:A"))
TextRange = "A1:D" & Count
'when writing text files you need to replace any quotation marks
'that the user may have entered : I use apostrophy instead
Sheets("DATA").Range(TextRange).Replace What:=Chr$(34), Replacement:=("'"), _
SearchOrder:=xlByColumns, MatchCase:=True
'create a filename
FName = Application.UserName & Format(Date, "dd-mm-yy") & ".txt"
Path = ThisWorkbook.Path & FName
Fnum = FreeFile ' Get unused file number
'On Error GoTo Done
Open Path For Output As #Fnum
For Rw = 1 To Count
For Cl = 1 To 4
TextData(Cl) = Sheets("DATA").Cells(Rw, Cl)
Next
MsgBox (TextData(1))
Write #Fnum, TextData(1), TextData(2), TextData(3), TextData(4)
Next
Done: Err.Clear: Close #Fnum: On Error GoTo 0
ALLON
End Sub
Public Sub TextLoad()
Range("A:D").ClearContents
ALLOFF
Rw = 1
FName = Application.UserName & Format(Date, "dd-mm-yy") & ".txt"
Path = ThisWorkbook.Path & FName
Fnum = FreeFile ' Get unused file number
On Error GoTo Done
Open Path For Input As #Fnum
Do While Not EOF(1) ' read in file until finished
Input #1, TextData(1), TextData(2), TextData(3), TextData(4)
For Cl = 1 To 4
Cells(Rw, Cl) = TextData(Cl)
Next
Rw = Rw + 1
Loop
Done: Err.Clear: Close #Fnum: On Error GoTo 0
ALLON
End Sub
Create a workbook with a sheet named "DATA"
insert dummy data in columns A:D
eg
CodeNo. Date operation complete
1 01-Jan see y
2 02-Jan hear n
3 03-Jan smell n
4 04-Jan touch y
insert a module and copy the code to it
***SAVE the wokbook***
Run 'TextDump' to save the text
Run 'TextLoad' to load the text
As you can see we are only saving text in columns A to D the rest of the worksheet may contain formulas, hyperlinks etc and will remain intact. Other sheets may be graphs or tables that reference the text columns A:D on sheets 'DATA'
this is a much simpler way for multiple users to acces all the formatting and links of a custom workbook without having write access to the workbook
For user friendly no-fuss insert this code in the 'BeforeSave' workbook event code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call TextDump
Cancel = True
End Sub
This will Dump the text file and prevent the XLWorkbook from saving
As I mentioned in my previous post I usually add an INDEX sheet which loads all the text files for the USER to choose from (more code needed for this).
One last point, sharing a workbook makes it extremely large and very user UNfreindly, if you simply dump each users input as text you can check with worksheet change selection event for file datetime and load in new data if it has been saved. I have Common Wokbooks with up to 20 Users at a time and they all see the same data instantly.
Hope you can follow this, and yes I tested the code!!!!!!