A "Virtual" Solution

B

Brendon Thiede

This post is a bit old, but if anyone stumbles across it (as I did) you can try this solution. I created a "User Defined" function that just displays a series of spaces. I also created a sub that when run will swap between the the "virtual tab" and an ASCII tab. In general though, if you have an app that reads the file and treats tabs specially, I would think the best solution would be to use different columns (rather than tabs) and then save a copy as tab-delimited text. Anyway, here's the code:

Option Explicit

Const TAB_INDENT_STRING As String = " "

Public Function VirtualTab() As String
VirtualTab = TAB_INDENT_STRING
End Function


Public Sub ToggleVirtualTabs()
Dim rng As Range
Set rng = Cells.Find(What:="CHAR(9)", LookIn:=xlFormulas, LookAt:=xlPart, MatchCase:=False)

If rng Is Nothing Then
Set rng = Cells.Find(What:="VirtualTab()", LookIn:=xlFormulas, LookAt:=xlPart)
If Not rng Is Nothing Then
Cells.Replace What:="VirtualTab()", Replacement:="CHAR(9)", LookAt:=xlPart, MatchCase:=False
End If
Else
Cells.Replace What:="CHAR(9)", Replacement:="VirtualTab()", LookAt:=xlPart, MatchCase:=False
End If
Set rng = Nothing
End Sub
 
Top